Reputation: 437
So this is a simple question, I've searched for the answer but couldn't find anything which explains what is the correct way to write the resources in routes.
I will explain my dilemma: assuming you have a UserController and PostController which extends it:
PostController extends UserController
now I understood the correct way to write the resources in the routes file is this:
//restful:
Route::resource('user', 'UserController');
Route::resource('user.post', 'PostController');
but when I do this, my artisan routes looks like this:
GET|HEAD user/{user}/post | user.post.index | PostController@index
GET|HEAD user/{user}/post/create | user.post.create | PostController@create
POST user/{user}/post | user.post.store | PostController@store
GET|HEAD user/{user}/post/{post} | user.post.show | PostController@show
GET|HEAD user/{user}/post/{post}/edit | user.post.edit | PostController@edit
PUT user/{user}/post/{post} | user.post.update | PostController@update
PATCH user/{user}/post/{post} | | PostController@update
DELETE user/{user}/post/{post} | user.post.destroy | PostController@destroy
Meaning I need to send 2 parameter through the route, that's all ok, but when I write my PostController I get this problem:
'ErrorException' with message 'Declaration of PostController::show() should be compatible with UserController::show($id)'
My question is, how am I supposed to pass 2 parameters if the declaration of PostController show and UserController show, are ought to be the same?
Upvotes: 0
Views: 52
Reputation: 6223
There's no reason for your PostController
to extend your UserController
.
The actual problem here is that the signatures for PostController::show()
and UserController::show()
don't match. If you're injecting models, chances are, it's because one has Post
and the other User
, or whatever your model names are.
Upvotes: 1