我在项目中使用Laravel 5.2 因此,当我尝试以登录形式登录时,它会继续加载并向同一页面唱歌而不是仪表板! 我一直试图解决这个问题,但没有成功 请帮帮我
我的Route.php代码
Route::get('/', ['as'=>'/','uses'=>'LoginController@getLogin']);
Route::post('login',['as'=>'login','uses'=>'LoginController@postLogin']);
//Route::get('/noPermission',function(){
// return view('permission.noPermission');
//});
Route::group(['middleware'=>['authen','roles']],function(){
Route::get('/logout',['as'=>'logout','uses'=>'LoginController@getLogout']);
Route::get('/dashboard',['as'=>'dashboard','uses'=>'DashboardController@dashboard']);
});
这是我的登录控制器代码
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Auth;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $username = 'username';
protected $redirectTo = '/dashboard';
protected $guard = 'web';
public function getLogin()
{
if (Auth::guard('web')->check())
{
return redirect()->route('dashboard');
}
return view('login');
}
public function postLogin(Request $request)
{
$auth= Auth::guard('web')->attempt(['username'=>$request->username,
'password'=>$request->password,
'active'=>1] );
if($auth)
{
return redirect()->route('dashboard');
}
return redirect()->route('/');
}
public function getLogout()
{
Auth::guard('web')->logout();
return redirect()->route('/');
}
}
我的信息中心代码
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class DashboardController extends Controller
{
public function __construct()
{
$this->middleware('web');
}
public function dashboard()
{
return view('layouts.master');
}
}
这是我的checkrole.php代码
<?php
namespace App\Http\Middleware;
use Closure;
class CheckRole
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$roles=$this->getRequiredRoleForRoute($request->route());
if($request->user()->hasRole($roles) || !$roles)
{
return $next($request);
}
return redirect('/noPermission');
}
private function getRequiredRoleForRoute($route)
{
$actions= $route->getAction();
return isset($actions['roles']) ? $actions['roles'] : null;
}
}