Search code examples
laravelrouteslaravelcollective

Sending post and passing address as route


I have the routes

Route::get('/login', 'LoginController@index');
Route::post('/login', 'LoginController@login');

the get to display my my login screen and the post for submission.

This is my controller login

 public function index(){
       return view('Login.index');
 }

 public function login(Request $request)
 {

 }

How can I get my form to send requests to this controller via the route? I'm trying this way

{!! Form::open(['id'=>'Formulario','route' => ['login.login'],'class'=>'form']) !!}

but the following error occurs

Route [login.login] not defined.


Solution

  • Name the route to make it work:

    Route::post('/login', 'LoginController@login')->name('login.login');
    

    Or:

    Route::post('/login', ['as' => 'login.login', 'uses' => 'LoginController@login']);