Answer the question
In order to leave comments, you need to log in
How to add a model object to a link?
Created Resource Controller, registered routing in web.
It looks like this: Route::resource('teams','TeamController');
As I understand from the documentation, routes and names for them have been created.
I want to add to my view in front of each element from the model a button like "Edit, delete, view"
I do it like this:
@foreach($teams as $team)
<tr>
<td>{{$team->name}}</td>
<td>{{$team->score}}</td>
<td>
<a class="btn btn-info" href="{{ route("teams.show/{$team}") }} ">Show</a>
{{--<a class="btn btn-danger" href="{{ route("teams.destroy/{$team}") }}">Delete</a>--}}
<a class="btn btn-info" href="{{ route("teams.edit/{$team}/edit") }}">Update</a>
</td>
</tr>
@endforeach
Route [show/{"id":8,"name":"Zorya","score":15}] not defined. (View: H:\xampp\htdocs\hockeyapp\resources\views\teams\index.blade.php)
Answer the question
In order to leave comments, you need to log in
Autobinding of models works in the routes file ( https://laravel.com/docs/5.4/routing#route-model-b... in generating links, everything is the same, you need to pass the id.
For some reason, you substitute the model id in the route name , and don't pass it as the second argument: https://laravel.com/docs/5.4/routing#named-routes
There is no point in using autobinding, you will confuse yourself, and there are no bonuses.
href="{{ route("teams.show", ["id"=>$team->id]) }}
Same with delete.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question