I'm new in laravel and I try to build a simple Authentication. All the things works fine except when using AuthController's action to log out, it just simply doesn't work. I have a nav bar which checks for Auth::check() and it doesn't change after calling the log out action and it stocks in home page. but after making few changes like deleting this manual logout code in SessionController:
public function logout()
{
Auth::logout();
Session::flush();
return redirect()->intended('login');
}
and changing the rout from this:
Route::get('logout', 'SessionsController@logout');
to this:
Route::get('auth/logout', 'Auth\AuthController@logout');
it throws this error:
BindingResolutionException in Container.php line 749: Target [Illuminate\Contracts\Auth\Registrar] is not instantiable.
I have this route inside the routes.php file:
Route::get('auth/logout', 'Auth\AuthController@logout');
and my AuthController is the controller that laravel providing us.
my SessionsController that handled logout before the changes but actually not work either is:
<?php namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class SessionsController extends Controller
{
/**
* Create a new sessions controller instance.
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Show the login page.
*
* @return \Response
*/
public function login()
{
return view('auth.login');
}
/**
* Perform the login.
*
* @param Request $request
* @return \Redirect
*/
public function postLogin(Request $request)
{
$this->validate($request, ['username' => 'required|exists:users', 'password' => 'required']);
if ($this->signIn($request)) {
flash('Welcome back!');
return redirect()->intended('dashboard');
}
flash('Could not sign you in.');
return redirect()->back();
}
/**
* Destroy the user's current session.
*
* @return \Redirect
*/
public function logout()
{
Auth::logout();
Session::flush();
return redirect()->intended('login');
}
/**
* Attempt to sign in the user.
*
* @param Request $request
* @return boolean
*/
protected function signIn(Request $request)
{
return Auth::attempt($this->getCredentials($request), $request->has('remember'));
}
/**
* Get the login credentials and requirements.
*
* @param Request $request
* @return array
*/
protected function getCredentials(Request $request)
{
return [
'username' => $request->input('username'),
'password' => $request->input('password'),
'verified' => true
];
}
}
And here is the AuthController __construct method:
public function __construct(Guard $auth, Registrar $registrar)
{
$this->auth = $auth;
$this->registrar = $registrar;
$this->middleware('guest', ['except' => ['logout', 'getLogout']]);
}
Please help me as soon as possible. Any help would be appreciated.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire