Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

amit123's avatar

useful routing in Laravel

hey guys,

I am Working on my first Laravel project and I am also new to routing and controllers at all.

Well, at the beginning I had a UsersController withe the functions create, store, update and so on and in http/requests/ a UserRequest. All users were by default customers. Then I had to do the same for users that were employees. First I used the same store and update function for both of them and put a lot if-Conditions in those functions for almost any input.

What I actually had to do is creating customerRequest and EmployeeRequest instead of one UserRequest and having in my Userscontrollers the functions StoreCustomer and StoreEmployee instead of just store.

I tried adding this line to the routes: Route::post('users/{user}', 'UsersController@storeCustomer');

and I get, when submitting : BadMethodCallException Method [store] does not exist.

But how do I tell laravel which function it has to take?

0 likes
7 replies
tuneless's avatar

you should show your Controller methods ;-)

method name comes after the @

UsersController@storeCustomer

so storeCustomer would be the method in UsersController here.

amit123's avatar

Route::get('/', function () {

return redirect('/users');

});

Route::get('/users/{user}/password', 'UsersController@password');

Route::get('/users/{user}/delete', 'UsersController@delete');

Route::get('/users/{user}/new-password', 'UsersController@createPassword');

Route::post('/users/{user}/new-password', 'UsersController@updatePassword');

Route::get('/users/create/customer', 'UsersController@createCustomer');

Route::get('/users/create/employee', 'UsersController@createEmployee');

Route::resource('/users', 'UsersController');

// added now

Route::post('users/{user}', 'UsersController@storeCustomer');

tuneless's avatar

You should watch your route definitions, there is a hirachie and you are overriding your routes.

You should watch this video, It's a bit advanced, but you will get an idea of routes structure and the hirachie: https://streamacon.com/video/laracon-us-2017/day-1-adam-wathan

I liked this video so much, because you will have the best structure in controllers. You need at least 2 new Controller in your example, to get rid of those problems you have now, with that approach.

amit123's avatar

Will watch both videos at home. right now it's not possible. another question to the controllers: in my DB I still have only one users Table with a column type that can have values 'customer' and 'employee'

It is still possible, if I have two controllers?

Please or to participate in this conversation.