Question

I would like to create an action to handle login POST requests. I don't know what am i doing wrong but, i can't handle/print any request in my postLogin action.I am newbie in Laravel, maybe i don't understand the concept of Laravel, but request handling(route base request handling) via routes is so stranger for me.

I would like to process POST data in my controller's action not in routes!

UserController.php

  public function postLogin()
  {
     $user = array(
            'email' => Input::get('email'),
            'password' => Input::get('password')
        );

     print_r($user);
     exit('1');
  }

Routes.php

//invoke action to handle post request
Route::post('login','UserController@login');

//render the view
Route::get('user/login', function()
{
  return View::make('user.login');
});

login.balde.php

     {{ Form::open(array('url' => 'user/login', 'files' => false,'name'=>'postLogin'))}}
    ...
    ..
 {{Form::submit('LogIn',array('class'=>'btn btn-primary btn-lg'));}}
       {{ Form::close() }}
Was it helpful?

Solution

routing with Laravel is a very simple, I'll try to explain it and I hope it will not look strange anymore. let's first make a route like you did:

Route::post('login','UserController@login');

by this we mean that for every post request to the link "yourWebsiteAddress/login" the function login() in your UserController will be executed. So you should have a function login() in the UserController. To test if this function is being called, just return a string:

public function login(){
    return 'login is working!';
}

or just dump the input

public function login(){
    $input = Input::all();
    return dd($input);
}

now in your form the url must be and existing route

{{ Form::open(array('url' => 'login')) }}
     {{ Form::submit('Submit') }}
{{ Form::close() }}

I hope this will be helpful

OTHER TIPS

I'm not sure if I understand but:

In your form is action user/login but in route is login (from is post request) try change it to login and in routes changelogin to postLogin

// line routes
Route::post('login','UserController@postLogin');

// line login.blade.php
{{ Form::open(array('url' => 'login', 'files' => false,'name'=>'postLogin'))}}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top