When I login to the system using Laravel 5.1 I logged in but session is not created I don't know what's the problem. I'm using AuthController with a little customization. This is the controller:
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'username' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:3',
'password_confirmation' => 'required|same:password',
]);
}
public function postLogin(Request $request)
{
$this->validate($request, [
'username' => 'required|alpha_num|max:255',
'password' => 'required|between:4,10',
]);
if (\Auth::attempt($request->only(['username', 'password']))) {
return redirect()->intended('/events');
}
return redirect()->back()->withInput()->with('error', 'Username Or Password is wrong!');
}
And this is the middleware
class UserMiddleware
{ /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if ($request->input('role') == 'admin') { return redirect('/dashboard'); } elseif ($request->input('role') == 'faculty') { return redirect('/events'); } elseif ($request->input('role') == 'student') { return redirect('/news'); }
return $next($request);
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire