@@ -13,21 +13,17 @@ class AdminController extends Controller
13
13
{
14
14
use AuthenticatesUsers;
15
15
16
- protected $ redirectTo = '/admin ' ;
16
+ // protected $redirectTo = '/admin';
17
17
public function __construct ()
18
18
{
19
- $ this ->middleware ('guest ' );
20
- $ this ->middleware ('guest:admin ' );
19
+ $ this ->middleware ('guest ' )-> except ( ' logout ' ); ;
20
+ // $this->middleware('guest:admin')->except('logout ');
21
21
22
22
}
23
- /**
24
- * Display a listing of the resource.
25
- *
26
- * @return \Illuminate\Http\Response
27
- */
28
- public function index ()
23
+
24
+ public function getContent ()
29
25
{
30
- //
26
+ return \view ( ' admin_layout ' );
31
27
}
32
28
33
29
public function getLoginForm ()
@@ -44,15 +40,27 @@ protected function createAdmin(Request $request)
44
40
]);
45
41
return redirect ()->intended ('login/admin ' );
46
42
}
47
- /**
48
- * Show the form for creating a new resource.
49
- *
50
- * @return \Illuminate\Http\Response
51
- */
52
- public function create ()
43
+
44
+ public function logout ()
53
45
{
54
- //
46
+ try {
47
+ $ this ->guard ()->logout ();
48
+ session ()->flush ();
49
+ return response ()->json ([
50
+ 'success ' => true ,
51
+ 'message ' => 'Admin Logout Successfully '
52
+ ], 200 );
53
+
54
+ } catch (\Throwable $ th ) {
55
+ return response ()->json ([
56
+ 'success ' => false ,
57
+ 'message ' => 'Admin Logout Failed '
58
+ ], 402 );
59
+ }
55
60
}
61
+ protected function guard (){
62
+ return Auth::guard ('admin ' );
63
+ }
56
64
57
65
/**
58
66
* Store a newly created resource in storage.
@@ -69,54 +77,16 @@ public function login(Request $request)
69
77
70
78
if (Auth::guard ('admin ' )->attempt (['email ' => $ request ->email , 'password ' => $ request ->password ], $ request ->get ('remember ' ))) {
71
79
72
- return redirect ()->intended ('/admin ' );
80
+ return response ()->json ([
81
+ 'success ' => true ,
82
+ 'message ' => 'Admin Login Successfully ' ,
83
+ 'user ' => Auth::guard ('admin ' )->user ()
84
+ ], 200 );
73
85
}
74
86
return back ()->withInput ($ request ->only ('email ' , 'remember ' ));
75
87
76
88
}
77
89
78
- /**
79
- * Display the specified resource.
80
- *
81
- * @param \App\Models\Admin $admin
82
- * @return \Illuminate\Http\Response
83
- */
84
- public function show (Admin $ admin )
85
- {
86
- //
87
- }
88
-
89
- /**
90
- * Show the form for editing the specified resource.
91
- *
92
- * @param \App\Models\Admin $admin
93
- * @return \Illuminate\Http\Response
94
- */
95
- public function edit (Admin $ admin )
96
- {
97
- //
98
- }
99
90
100
- /**
101
- * Update the specified resource in storage.
102
- *
103
- * @param \Illuminate\Http\Request $request
104
- * @param \App\Models\Admin $admin
105
- * @return \Illuminate\Http\Response
106
- */
107
- public function update (Request $ request , Admin $ admin )
108
- {
109
- //
110
- }
111
91
112
- /**
113
- * Remove the specified resource from storage.
114
- *
115
- * @param \App\Models\Admin $admin
116
- * @return \Illuminate\Http\Response
117
- */
118
- public function destroy (Admin $ admin )
119
- {
120
- //
121
- }
122
92
}
0 commit comments