1

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>')
2
  • I think you're missing a colon after $id).' " should be $id).' " ' Commented Nov 12, 2015 at 20:26
  • Thanks, but no. That's not the problem. The colons are ok :) Commented Nov 12, 2015 at 20:36

2 Answers 2

4

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

->editColumn('nom', '<a href="{{ route("categorie-afficher",["id"=>$id]) }}" >{{$nom}}</a>')
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but it's not working. It gives [Undefined variable: id]. it works when i put an integer instead of $id: ->editColumn('nom', '<a href="'.route('article-afficher', 1).'">{{$nom}}</a>')
@Keyser_Soze Sorry, you are right. I have updated answer. Just, like in other blade views - wrap it with {{ route(...) }}.
thanks! this is the final code: ->editColumn('nom', '<a href=" {{route(\'categorie-afficher\', $id)}}">{{$nom}}</a>')
0

just add

->rawColumns(['name'])

after edit

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.