Skip to content

Commit 76d4586

Browse files
committed
Vuex Module tested & Category Adding , Retreving Done
1 parent bbf797f commit 76d4586

33 files changed

+2813
-716
lines changed

app/Exceptions/Handler.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public function register()
3535
{
3636

3737
}
38-
protected function unauthenticated($request, AuthenticationException $exception)
39-
{
40-
if ($request->expectsJson()) {
41-
return response()->json(['error' => 'Unauthenticated.'], 401);
42-
}
43-
if ($request->is('admin') || $request->is('admin/*')) {
44-
return redirect()->guest('/login/admin');
45-
}
38+
// protected function unauthenticated($request, AuthenticationException $exception)
39+
// {
40+
// if ($request->expectsJson()) {
41+
// return response()->json(['error' => 'Unauthenticated.'], 401);
42+
// }
43+
// // if ($request->is('admin') || $request->is('admin/*')) {
44+
// // return redirect()->guest('/login/admin');
45+
// // }
4646

47-
return redirect()->guest(route('login'));
48-
}
47+
// return redirect()->guest(route('login'));
48+
// }
4949
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

3-
namespace App\Http\Controllers;
3+
namespace App\Http\Controllers\Admin;
44

5+
use App\Http\Controllers\Controller;
56
use App\Models\Category;
67
use Illuminate\Http\Request;
78

@@ -14,18 +15,9 @@ class CategoryController extends Controller
1415
*/
1516
public function index()
1617
{
17-
//
18+
return Category::latest()->get();
1819
}
1920

20-
/**
21-
* Show the form for creating a new resource.
22-
*
23-
* @return \Illuminate\Http\Response
24-
*/
25-
public function create()
26-
{
27-
//
28-
}
2921

3022
/**
3123
* Store a newly created resource in storage.
@@ -35,51 +27,45 @@ public function create()
3527
*/
3628
public function store(Request $request)
3729
{
38-
//
30+
$this->validate($request , [
31+
'name' => 'bail|required|min:3'
32+
]);
33+
return Category::create($request->all());
3934
}
4035

4136
/**
4237
* Display the specified resource.
4338
*
44-
* @param \App\Models\Category $category
39+
* @param int $id
4540
* @return \Illuminate\Http\Response
4641
*/
4742
public function show(Category $category)
4843
{
49-
//
44+
return $category;
5045
}
5146

52-
/**
53-
* Show the form for editing the specified resource.
54-
*
55-
* @param \App\Models\Category $category
56-
* @return \Illuminate\Http\Response
57-
*/
58-
public function edit(Category $category)
59-
{
60-
//
61-
}
47+
6248

6349
/**
6450
* Update the specified resource in storage.
6551
*
6652
* @param \Illuminate\Http\Request $request
67-
* @param \App\Models\Category $category
53+
* @param int $id
6854
* @return \Illuminate\Http\Response
6955
*/
7056
public function update(Request $request, Category $category)
7157
{
72-
//
58+
return $category->update($request->all());
7359
}
7460

7561
/**
7662
* Remove the specified resource from storage.
7763
*
78-
* @param \App\Models\Category $category
64+
* @param int $id
7965
* @return \Illuminate\Http\Response
8066
*/
8167
public function destroy(Category $category)
8268
{
83-
//
69+
return $category->delete();
8470
}
8571
}

app/Http/Controllers/AdminController.php

+30-60
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,17 @@ class AdminController extends Controller
1313
{
1414
use AuthenticatesUsers;
1515

16-
protected $redirectTo = '/admin';
16+
// protected $redirectTo = '/admin';
1717
public function __construct()
1818
{
19-
$this->middleware('guest');
20-
$this->middleware('guest:admin');
19+
$this->middleware('guest')->except('logout');;
20+
// $this->middleware('guest:admin')->except('logout');
2121

2222
}
23-
/**
24-
* Display a listing of the resource.
25-
*
26-
* @return \Illuminate\Http\Response
27-
*/
28-
public function index()
23+
24+
public function getContent()
2925
{
30-
//
26+
return \view('admin_layout');
3127
}
3228

3329
public function getLoginForm()
@@ -44,15 +40,27 @@ protected function createAdmin(Request $request)
4440
]);
4541
return redirect()->intended('login/admin');
4642
}
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()
5345
{
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+
}
5560
}
61+
protected function guard(){
62+
return Auth::guard('admin');
63+
}
5664

5765
/**
5866
* Store a newly created resource in storage.
@@ -69,54 +77,16 @@ public function login(Request $request)
6977

7078
if (Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password], $request->get('remember'))) {
7179

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);
7385
}
7486
return back()->withInput($request->only('email', 'remember'));
7587

7688
}
7789

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-
}
9990

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-
}
11191

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-
}
12292
}

app/Http/Kernel.php

+1
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,6 @@ class Kernel extends HttpKernel
6262
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
6363
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
6464
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
65+
'isAdmin' => \App\Http\Middleware\IsAdmin::class,
6566
];
6667
}

app/Http/Middleware/IsAdmin.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Closure;
6+
use Illuminate\Http\Request;
7+
use Illuminate\Support\Facades\Auth;
8+
9+
10+
class IsAdmin
11+
{
12+
/**
13+
* Handle an incoming request.
14+
*
15+
* @param \Illuminate\Http\Request $request
16+
* @param \Closure $next
17+
* @return mixed
18+
*/
19+
public function handle(Request $request, Closure $next)
20+
{
21+
22+
23+
if (!Auth::guard('admin')->check()) {
24+
if ($request->ajax()) {
25+
return response()->json([
26+
'message' => 'Authenticate Failed'
27+
],401);
28+
} else {
29+
return redirect('login/admin');
30+
}
31+
32+
}
33+
// return response()->json(['st' => Auth::guard('admin')->check()], 200);;
34+
return $next($request);
35+
36+
}
37+
}

app/Models/Brand.php

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
class Brand extends Model
99
{
1010
use HasFactory;
11+
protected $guarded = [];
1112
}

app/Models/Category.php

+2
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
class Category extends Model
99
{
1010
use HasFactory;
11+
12+
protected $guarded = [];
1113
}

app/Models/Tag.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class Tag extends Model
9+
{
10+
use HasFactory;
11+
protected $guarded = [];
12+
}

app/Providers/RouteServiceProvider.php

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public function boot()
4242
->middleware('api')
4343
->namespace($this->namespace)
4444
->group(base_path('routes/api.php'));
45+
// Customised Route
46+
// Route::prefix('admin')
47+
// ->middleware('isAdmin')
48+
// ->namespace($this->namespace)
49+
// ->group(base_path('routes/admin.php'));
4550

4651
Route::middleware('web')
4752
->namespace($this->namespace)

0 commit comments

Comments
 (0)