我只希望授权用户登录仪表板,但是在我的代码中,即使使用/ dashboard输入网址,也可以访问仪表板,但我只希望管理员用户访问它。 以下是我的代码:
//controller
<?php
class AccountController extends BaseController{
public function login(){
$data = Input::all();
$rules = array(
'email' => 'required|email',
'password' => 'required|min:6'
);
$validator = Validator::make($data, $rules);
if($validator->fails()){
return Redirect::to('/login')->withInput(Input::except('password'))->withErrors($validator);
}//end of if
else{
$userdata = array(
'email'=>Input::get('email'),
'password'=>Input::get('password')
);
if(Auth::validate($userdata)){
if(Auth::attempt($userdata)){
return Redirect::to('/dashboard');
}//end of inner if2
}//end of inner if1
else{
Session::flash('error','Somthing went wrong');
return Redirect::to('login');
}//end of inner else1
}//end of else
}
public function logout(){
Auth::logout();
return Redirect::to('login');
}
}//end of the class
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::get('/', function()
{
return View::make('login');
});
Route::get('/login', function()
{
return View::make('login');
});
Route::post('login','AccountController@login');
Route::get('/dashboard', function()
{
return View::make('dashboard');
});
Route::get('logout',array('uses'=>'AccountController@logout'));
请帮我解决这个问题
答案 0 :(得分:0)
创建需要用户登录Access的路由组。
Route::group(array('before' => 'auth'), function(){
Route::get('/dashboard', function()
{
return View::make('dashboard');
});
});
使用Auth进行过滤之前,只能限制登录用户。