다음은 맞춤형 인증 솔루션입니다.
class AdminsController extends Controller
{
public function getLogin()
{
return view('admin.login');
}
public function postLogin(Request $request)
{
$this->validate($request, ['email' => 'required|email', 'password' => 'required']);
if(!Auth::attempt(['email' => $request['email'], 'password' => $request['password']])) {
return redirect()->back()->with(['fail' => 'Could not log you in!']);
}
return redirect()->route('admin.dashboard');
}
public function getLogout()
{
Auth::logout();
return redirect()->route('index');
}
}
그리고 routes.php에서
:
Route::group(['middleware' => ['guest']], function() {
Route::get('/admin/login', [
'uses' => '[email protected]',
'as' => 'admin.login'
]);
Route::post('/admin/login', [
'uses' => '[email protected]',
'as' => 'admin.login'
]);
});
Route::group(['middleware' => ['auth']], function() {
Route::get('/admin/logout', [
'uses' => '[email protected]',
'as' => 'admin.logout'
]);
});
는이 코드 주위에 얻을 것이 도움이되었다 있기를 바랍니다.
이미 인증 시스템 (register, login ...)이 잘 작동하고 있습니다. 난 단지 누군가가 성공적으로 로그인 할 때마다 호출되는 사용자 정의 함수를 추가하려고합니다. > JSON ([ '- '보호 기능 인증되지 않은 ($ 요청 포함한 AuthenticationException $ 예외) { 경우 ($ 요청 -> expectsJson()) { 반환 응답() : – Tobi