I don't think this post How do I override laravel resource route default method? solves my problem.
Normal resource route is that "index" shows all items. What I want to do is have "index" show all related items for a particular id.
So when I select a classroom from the list, I want the index action that I'm calling, to show, as it's index function, all the people for that specific classroom.
So I replaced the default resource route
//Route::resources(['attendees' => 'attendeesController']);
with
Route::resource('attendees', 'attendeesController')->names([
'index' => 'attendees.index',
'store' => 'attendees.store',
'create' => 'attendees.create',
'show' => 'attendees.evaluation',
'update' => 'attendees.update',
'destroy' => 'attendees.destroy',
'edit' => 'attendees.edit',
]);
So in my controller, I have this:
public function index(Request $request,$id)
{
dd($request);
...
}
And in my view of classrooms, on a particular classroom id I have this
<a href="{{route('attendees.index', ['classroom' => $data->id])}}">{{$data->Reference}}
- As far as I can see, I'm passing the parameter to the controller.
- And the controller is setup to expect a $id parameter
So why am I getting this? I'm guessing something pretty basic, but I can't see what.
Type error: Too few arguments to function
App\Http\Controllers\AttendeesController::index(),
1 passed and exactly 2 expected