Easy Column Links using linkTo()

Hey there! 👋 Do you want an easy way to deep link your Backpack columns? Well, you're in luck! Backpack has introduced a new column at...

Karan Datwani
Karan Datwani
Share:

Hey there! 👋

Do you want an easy way to deep link your Backpack columns? Well, you're in luck!

Backpack has introduced a new column attribute called linkTo(). This simplifies the process of linking columns to specific routes.

So you make UX better, while saving you from writing verbose code.

Introducing the linkTo() Attribute

Previously, linking a column to a route required the manual setup of the wrapper['href']. For instance:

CRUD::column('category')->wrapper([
    'href' => function ($crud, $column, $entry, $related_key) {
          return backpack_url('category/'.$related_key.'/show');
      },
]);

Isn't that a lot to handle while doing for many columns? Well, worry no more! With the new linkTo() attribute, now you can achieve the same functionality with a single line:

CRUD::column('category')->linkTo('category.show');

Yes, it's that simple! linkTo() checks if your named route requires a parameter and passes the related entry ID.

And, This works for 1-n relationship columns too:

CRUD::column('tags')->linkTo('tag.show');

But wait, there's more! You can pass additional parameters or use a closure instead of a route name. Take a look at these examples:

//Pass additional parameters to your URLs
CRUD::column('my_column')->linkTo('my.route.name', ['myParameter' => 'value']);

//Use a closure instead of a route name
CRUD::column('category')->linkTo(fn($entry, $related_key) => backpack_url('category/'.$related_key.'/show'));

Use it & Spread the love ❤️

Now you know it! Go, Deep link your admin panel and bring a huge UX improvement within a few minutes. Trust us, your admins will love you for it!

To know more, visit the docs.

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?