Why You Should Link Your CRUDs (And How to Do It with Backpack)

In every admin panel, you’re usually dealing with a bunch of CRUDs — customers, orders, invoices, etc. But when these CRUDs are disconn...

Karan Datwani
Karan Datwani
Share:

In every admin panel, you’re usually dealing with a bunch of CRUDs — customers, orders, invoices, etc. But when these CRUDs are disconnected, navigating between related data becomes a mess. You end up clicking around, opening new tabs, and losing track. 😵‍💫

Linking your CRUDs bridges that gap and keeps everything connected. It helps maintain data integrity and makes the admin experience way smoother.

Benefits of Linking CRUDs

  • Easy Navigation: Quickly jump between related records without manual searching.
  • Better Understanding: See how different pieces of data connect, providing clearer context
  • Time-Saving: Reduce the number of steps to perform related tasks
  • User Experience: Create a more intuitive and user-friendly interface

Let’s dive into some key use cases that show why and how you should link your CRUDs, with code examples for each.


How to Link CRUDs in Backpack

Backpack for Laravel offers straightforward methods to link CRUD operations. One of the simplest ways to link a related model is by using the linkTo method and Quick Button. Here are some common use cases with code examples:


1. Link a Single Relation Column

If you have a Customer model and want to make the customer name clickable, linking it directly to their profile page is super easy.


CRUD::column('customer.name')
    ->type('text')
+    ->linkTo('customer.show');

This makes the customer's name clickable, and users can easily jump to the customer’s details.


2. Link Multiple Related Items

What if you need to show multiple related columns and want to make each of them clickable? You can link multiple column values to their respective CRUDs like this.


CRUD::column('deals')->label('Deals')
    ->type('select_multiple')
    ->entity('deals')
    ->attribute('name')
    ->model(Deal::class)
+   ->linkTo(fn($entry) => backpack_url("deal/{$entry->id}/show"));

// Or simply
+ CRUD::column('deals')->linkTo('deal.show');

This links all the Deals associated with the Customer and sets individual link for each deal to click and view details.


3. Link Multi-Relation Count Column

You may want to show the count of related records—like how many Deals a customer has. You can link these count columns to a detailed list of those related records.


CRUD::column('deals')
        ->type('relationship_count')
        ->suffix(' Deal(s)')
+       ->linkTo(fn($entry) => backpack_url("customer/{$entry->id}/deals"));

I'm creating a custom link here which will take me to CustomerDeals Nested CRUD to show only deals of that customer.


4. Link to Filtered Data

Linking to a filter is powerful when you want to filter a list based on some condition. For example, the admin is viewing the categories list and linking the category name column will make it easy to navigate and view filtered customers in one click.


CRUD::column('status')->label('Status')
+     ->linkTo(fn($entry) => backpack_url('customer?type=active'));

You may have more logical filter set on your CRUD, give it a try, you will love it.


5. Link to Custom Actions

Add custom buttons for quick actions, like opening an external link. For example, here’s a button that opens a Google search with a pre-filled query.


CRUD::button('google')->stack('line')->view('crud::buttons.quick')->meta([
            'access' => true,
            'icon' => 'las la-search',
            'wrapper' => [
                'href' => function ($entry, $crud) {
                    return "www.google.com/search?q=$entry->name";
                },
            ],
        ]);

6. Add Top Button for Related CRUD

In my CRM, each company has multiple contact persons. And, I also have a ContactCRUD to view the complete contact list. However, I didn’t want to clutter the menu with too many items.


CRUD::addButton('top', 'contact', 'view', 'crud::buttons.quick')->meta([
            'access' => true,
            'label' => ' Contacts',
            'icon' => 'las la-address-card',
            'wrapper' => [
                'class' => 'btn btn-outline-primary',
                'href' => url('admin/contact'),
            ],
        ]);

So, I added a contact button at the top of CompanyCRUD, allowing easy switching to the contacts list view from there. You can see a similar setup here in the demo.


7. Link Back to Parent Item

On the invoice list, each invoice is tied to a client. So I linked the client name to their profile to make it easier to see all invoices in context:

CRUD::column('company.name')->label('Company Name')
+     ->linkTo('customer.show');

Super useful when you’re checking billing stuff and want to double-check past invoices, payment status, etc.


Conclusion

Linking your CRUDs isn’t just about making your admin panel look fancy—it’s about improving usability. You create a more connected and efficient admin panel. It simplifies navigation, provides better context, and improves overall user experience.

Whether it’s through linking related models, adding quick buttons, or even filtering, these small tweaks will make a huge difference in how your admin panel functions.

So, next time you're building with Backpack, ask yourself: How can I make these CRUDs talk to each other?

To know more, check out the Backpack documentation.

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?