oussama.tn
oussama.tn

Reputation: 299

Laravel 5.1 - datatables -Adding a link using editColumn

I'm using Laravel 5.1 with datatables (yajra/laravel-datatables-oracle). I want to add a link to the data in my table but its not working. I guess the problem is the manner i put the parameter, it should be different.

PS: When I remove the parameter, it works and show me the link: categorie/afficher

public function anyData()
{
  $categories = \App\Categorie::all();
  return Datatables::of($categories)
           ->editColumn('nom', '<a href="'.route('categorie-afficher', $id).'" >{{$nom}}</a>')
           ->make(true);
}

This is my route:

Route::get('/categorie/afficher/{id}', [
    'as' => 'categorie-afficher',
    'uses' => 'CategorieController@afficher'
]);

The program give an error: undefined $id. When I put an integer value instead of $id, it works!

 ->editColumn('nom', '<a href="'.route('categorie-afficher', 1).'">{{$nom}}</a>')

Upvotes: 1

Views: 3919

Answers (2)

brahim haddad
brahim haddad

Reputation: 1

just add

->rawColumns(['name'])

after edit

Upvotes: 0

voodoo417
voodoo417

Reputation: 12101

See generating URLs To Named Routes. In your case it should be:

->editColumn('nom', '<a href="{{ route("categorie-afficher",["id"=>$id]) }}" >{{$nom}}</a>')

Upvotes: 4

Related Questions