Laravel-datatables: Link to Route

Created on 29 Jan 2016  ·  4Comments  ·  Source: yajra/laravel-datatables

Is it possible to link directly to a route, for example...
->addColumn('namelink', function ($users) { return '<a href="redirect()->route('users.show').$users->id.'" ">'.$users->name.'</a>'; })

Just an example or something like that. Also what is the easiest way to link in the table so all the name result link to the show page as example.

Most helpful comment

Thanks for this snippet! Also, don't forget to call rawColumns for unescaped HTML

return Datatables::of(User::query())
    ->addColumn('namelink', function ($user) {
        return '<a href="' . route('users.show', $user->id) .'">'.$user->name.'</a>'; 
    })
    ->rawColumns(['namelink'])
    ->make(true);

All 4 comments

I think the problem here is you use redirect() and your route is not properly called. Just remove it and link should work fine.

->addColumn('namelink', function ($users) {
  return '<a href="' . route('users.show', $users->id) .'">'.$users->name.'</a>'; 
})

Thanks for this snippet! Also, don't forget to call rawColumns for unescaped HTML

return Datatables::of(User::query())
    ->addColumn('namelink', function ($user) {
        return '<a href="' . route('users.show', $user->id) .'">'.$user->name.'</a>'; 
    })
    ->rawColumns(['namelink'])
    ->make(true);
->editColumn('user_id', function ($data)  {
      return '<a href="/user/'.$data->user_id.'">'.$data->user_id.'</a>';
    })
    ->rawColumns(['action','user_id'])

working fine thank @jpuck and @yajra

Thanks Brothers for this love

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vipin733 picture vipin733  ·  3Comments

Abdulhmid picture Abdulhmid  ·  3Comments

jackrsantana picture jackrsantana  ·  3Comments

alejandri picture alejandri  ·  3Comments

t0n1zz picture t0n1zz  ·  3Comments