Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use custom function in Controller when using resource in routes - Laravel

Been building a framework website using Laravel and working on the user system.

I am using the controller by a resource route:

Route::resource('user', 'UserController');

Which works fine for all the normal create, index, store etc function in the controller.

For my registration form this is the opening:

{{ Form::open(array('route' => 'user.store', 'class'=>'small-form form-holder')) }}

Thinking how nice this is, I created a login function in my UserController and tried this for my login form:

{{ Form::open(array('route' => 'user.login', 'class'=>'small-form form-holder')) }}

However this returns a route not defined error. Is this because of the resource route that I set? I know I could set a custom route which uses the controllers login method but I like this way of doing things.

like image 404
Lovelock Avatar asked Mar 05 '15 11:03

Lovelock


1 Answers

Using Resource will generate following route names by default

user.index
user.create
user.store
user.show
user.edit
user.update
user.destroy

more information RESTful Resource Controllers

If you want to create another route you could do this way

Route::get('user/login', 'UserController@login');

Route::resource('user', 'UserController');

note: you should define those routes before your call to Route::resource

for more information you can look at RESTful Resource Controllers in Adding Additional Routes To Resource Controllers session

like image 67
mininoz Avatar answered Oct 07 '22 22:10

mininoz