php - laravel 4 authentication check always returns false -
i'm making application in laravel 4 , i've run problem.
so far have tried make authentication system. followed several tutorials none of them seem work. possibly because tutorial outdated (laravel evolving constantly).
here's situation:
i have login form, form authenticates user. , works fine, code in routes.php file.
route::post('login', function () { $user = array( 'e-mail' => input::get('e-mail'), 'password' => input::get('password') ); if (auth::attempt($user)) { return redirect::route('home') ->with('flash_notice', 'you logged in.'); } // authentication failure! lets go login page return redirect::route('login') ->with('flash_error', 'your username/password combination incorrect.') ->withinput(); });
so when log in go home page , message displayed, no problems there. in view have following code (i use blade this).
<ul> <li><a href="{{ url::to('home') }}">home</a></li> @if(auth::check()) <li><a href="{{ url::to('profile') }}">profile</a></li> <li><a href="{{ url::to('logout', 'logout ('.auth::user()->e-mail.')') }}">logout</a></li> @else <li><a href="{{ url::to('login') }}">login</a></li> @endif </ul>
the problem no matter auth::check() returns false. have researched problem several hours , don't know continue...
in user model getkey() method returns null, thought database might wrong. data being fetched perfectly.
thanks time.
as turns out silly mistake. laravel defines default primary key 'id' in smallcaps. id used in database defined 'id'.
i fixed changing field names in database. option define
protected $primarykey = 'id';
in model...
have nice day
Comments
Post a Comment