Laravel重定向回主页

时间:2014-04-27 16:26:07

标签: php redirect web laravel

我正在使用Laravel构建一个需要用户身份验证的应用程序。因此,我使用Auth库来制作它。然而,当我测试它时,当我试图签出它时,首先说“哎呀,看起来出事了!”只有当我精神焕发时才有效。

这是仪表板页面

@extends('layouts.default')
@section('navbar-content')
<ul class="nav navbar-nav">
<li class="active"><a href="{{ URL::route('Home') }}">Home</a></li>
<li><a href="{{ URL::route('GetSignOut') }}">Sign Out</a></li>
</ul>
<p class="navbar-text navbar-right">Signed in as <a href="" class="navbar-link">{{Auth::user()->name }}</a></p>
@stop

@section('content')
<div class="col-md-3">

</div>
<div class="col-md-6">

</div>
<div class="col-md-3">

</div>
@stop

路线:

<?php
Route::get('/', array ('as' => 'Home', 'uses' => 'HomeController@goHome'));
Route::get('/sign-in', array ('as' => 'GetSignIn', 'uses' => 'AuthController@getSignIn'));
Route::post('/sign-in', array('as' => 'PostSignIn', 'uses' => 'AuthController@postSignIn'));
Route::get('/sign-out', array('as' => 'GetSignOut', 'uses' => 'AuthController@getSignOut'));

身份验证控制器:

<?php 
class AuthController extends BaseController {
    public function getSignIn() {
        return View::make('sign-in');
    }

    public function postSignIn() {
        $validator = Validator::make(Input::all(), array(
            'email' => 'required|max:255',
            'password' => 'required'
        ));

        if ($validator->fails()) {
            return Redirect::route('GetSignIn')->withErrors($validator);
        }

        $auth = Auth::attempt(array(
            'email' => Input::get('email'),
            'password'  => Input::get('password')
        ), false);

        if (!$auth) {
            return Redirect::route('GetSignIn')->withErrors(array ('Invalid credentials'));
        }

        return Redirect::route('Home');
    }

    public function getSignOut() {
        Auth::logout();
        return Redirect::route('Home');
    }
}

1 个答案:

答案 0 :(得分:4)

看看this upgrade guide

您需要在nullable表格中添加remember_token VARCHAR(100)users列。