在登录laravel之前,Make无法访问url

时间:2015-01-09 04:27:01

标签: php laravel

我想让make无法访问&预订/输入'登录前

PassController.php

public function authenticate()
    {   
        $data= array('username'=>Input::get('username')'password' =>Input::get('password'));`
        if(Auth::attempt($data)) 
        {
            return Redirect::intended('book/input');
        } 
        else 
        {
            return Redirect::to('/')->with('error', 'Login failed')
        }

routes.php文件

Route::get('/', function()
{
    return View::make('book.login');
});

Route::get('book/input',function()
{
    return View::make('book.profile');
});

Route::post('book/auth', 'PassController@authenticate');

login.blade.php

{{Form::open(array('action' => 'PassController@authenticate')) }}
.....
{{Form::close() }}

登录成功,我只想登录用户,可以访问书籍/输入。如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

尝试这个,概念被称为过滤器,它首先检查用户是否登录,如果是,那么只允许该路由,否则它将重定向到登录页面或任何你想要的页面,你可以在filter.php文件中指定

Route::group(['before' => 'auth'], function ()
{
      Route::get('book/input',function()
      {
          return View::make('book.profile');
      });
});

有关过滤器的详细信息,请转到此链接

http://laravel.com/docs/4.2/routing#route-filters

http://culttt.com/2013/09/16/use-laravel-4-filters/