You are having trouble authenticating and logging users in Laravel 4.
My login form is being directed to this route.
Route::post('login', function() { // get POST data $userdata = array( 'username' => Input::get('username'), 'password' => Input::get('password') ); if ( Auth::attempt($userdata) ) { // we are now logged in, go to home return Redirect::to('/'); } else { // auth failure! lets go back to the login return Redirect::to('login') ->with('login_errors', true); // pass any error notification you want // i like to do it this way :) } });
At this point, everything seems to be going well. However, I am redirected to the home page, but the user object is not stored. If I try to access any custom function, I get the error message "Trying to get a non-object property."
Here is my user model
<?php use Illuminate\Auth\UserInterface; use Illuminate\Auth\Reminders\RemindableInterface; class User extends Eloquent implements UserInterface, RemindableInterface { protected $table = 'tblusers'; protected $key = 'userid'; protected $hidden = array('password'); public function getAuthIdentifier() { return $this->getKey(); } public function getAuthPassword() { return $this->password; } public function getReminderEmail() { return $this->email; } public function roles() { return $this->belongsToMany('Role'); } public function permissions() { return $this->hasMany('Permission'); } public function hasRole($key) { foreach($this->roles as $role){ if($role->name === $key) { return true; } } return false; } }
Some of the information I find is strange. If instead of redirecting to '/' I return View::make('home') it saves the object just fine, however, when I leave this page, it disappears again.
EDIT:
Since this should have something to do with sessions, I sent my session.php file for reference.
<?php return array( 'driver' => 'native', 'lifetime' => 5, 'files' => storage_path().'/sessions', 'connection' => null, 'table' => 'sessions', 'lottery' => array(2, 100), 'cookie' => 'laravel_session', 'path' => '/', 'domain' => null, 'payload' => 'laravel_payload', );
So far, I have tried cookies and native session drivers that are out of luck.