I created a custom guard in laravel the problem i am having with the custom guard is that when i check the remember me function on the login page, i can login in but when i want to sign out i can not terminate the session. I know that the problem is in the logout functionality but not sure how to fix the issue. I tried to copy the logout function in the authenticatesuser.php
but still wasn't able to terminate the session and log out.
logincontroller
<?php
namespace App\Http\Controllers\CustomerAuth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Auth;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
protected function guard()
{
return Auth()->guard('customer');
}
public function logoutcustomer()
{
$customer = Auth::guard($customer)->logout();
$customer->session()->invalidate();
return redirect('/');
}
public function showLoginForm()
{
if (Auth::user() || Auth::guard('customer')->user()) {
return redirect('/');
} else {
return view('customer-auth.login');
}
}
}
AuthenticatesUser.php
public function logout(Request $request)
{
$this->guard()->logout();
$request->session()->invalidate();
return redirect('/');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire