How to compare two CRUD entities.

Let's say I have a lengthy online form related to hiring for a particular position, and I received a good number of applicants. Now, lo...

Karan Datwani
Karan Datwani
Share:

Let's say I have a lengthy online form related to hiring for a particular position, and I received a good number of applicants. Now, looking at a glance, these records look very similar, which makes it a bit hard to compare. This is just one example; there could be other real-world scenarios where we want to compare records like specs, etc…

We have to thank Mauro Martinez for introducing the compare feature in Backpack. This handy tool lets the admin compare the records side by side, making it easy — from choosing the best candidates to finding the best product based on their features.

How to use

To use the compare feature in your backpack project:

  1. Install the compare operation package;
composer require maurohmartinez/compare-operation-backpack-laravel
  1. Inside your CrudController, add the trait;
+ use \MHMartinez\CompareOperation\CompareOperation;
  1. And then add the columns to setupCompareOperation() just like you'd do with the Show Operation:
protected function setupCompareOperation(): void
{
    $this->crud->column('id');
    $this->crud->column('name');
    $this->crud->column('email');
    // or...
    // $this->setupShowOperation();
}

And... we are all set to compare!👨‍💻🙃

With just a few simple steps, workflow can be made more efficient and side-by-side comparisons can be made easy.

Conclusion

The Comparison feature in Backpack is ready to lend a hand when the data gets messy. With just a few steps, you can easily set up side-by-side comparisons using Mauroh's compare operation. Happy Coding!

Want to receive more articles like this?

Subscribe to our "Article Digest". We'll send you a list of the new articles, every week, month or quarter - your choice.

Reactions & Comments

What do you think about this?

Latest Articles

Wondering what our community has been up to?