serefayazgun Şöyle olabilir:
class LoginAsCustomerController extends Controller
{
public function login(Request $request, $id)
{
$customer = User::findOrFail($id);
$admin = $request->user();
$cacheKey = sprintf("proxy_login.%s.%s",
hash('sha256', $request->userAgent() . $request->ip()),
$customer->id
);
Cache::remember($cacheKey, 60 * 60, function () use ($admin) {
return $admin->id;
});
Auth::login($customer);
$request->session()
->regenerate();
return redirect()->route('customer.dashboard')
->with('admin_login', __(':name adına giriş yaptınız.', [
'name' => $customer->name,
]));
}
public function logout(Request $request)
{
$customer = $request->user();
$cacheKey = sprintf("proxy_login.%s.%s",
hash('sha256', $request->userAgent() . $request->ip()),
$customer->id
);
$adminId = Cache::pull($cacheKey);
$admin = User::findOrFail($adminId);
Auth::login($admin);
$request->session()
->regenerate();
return redirect()->route('admin.dashboard')
->with('admin_logout', __('Admin paneline başarıyla geri döndünüz.'));
}
}