"Added admin type checks and redirects in AdminController and MainController; updated product views and admin header"
This commit is contained in:
parent
5af3b7ef9c
commit
f214f8aab4
@ -10,13 +10,19 @@ class AdminController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if (session()->get('type') == 'Admin') {
|
||||
return view('Dashboard.index');
|
||||
}
|
||||
return redirect()->back();
|
||||
}
|
||||
public function products()
|
||||
{
|
||||
if (session()->get('type') == 'Admin') {
|
||||
$products = Product::all();
|
||||
return view('Dashboard.products', compact('products'));
|
||||
}
|
||||
return redirect()->back();
|
||||
}
|
||||
// public function addNewProduct()
|
||||
// {
|
||||
// $validated = request()->validate([
|
||||
@ -58,6 +64,7 @@ class AdminController extends Controller
|
||||
//mass assignment for adding new product
|
||||
public function addNewProduct(Request $request)
|
||||
{
|
||||
if (session()->get('type') == 'Admin') {
|
||||
$validated = $request->validate([
|
||||
'name' => 'required',
|
||||
'price' => 'required|numeric',
|
||||
@ -79,6 +86,8 @@ class AdminController extends Controller
|
||||
|
||||
return redirect()->back()->with('success', 'Product Added Successfully');
|
||||
}
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
||||
//normal assignment for update
|
||||
@ -114,6 +123,7 @@ class AdminController extends Controller
|
||||
//mass assignment for update
|
||||
public function updateProduct(Request $request)
|
||||
{
|
||||
if (session()->get('type') == 'Admin') {
|
||||
$validated = $request->validate([
|
||||
'name' => 'required',
|
||||
'price' => 'required|numeric',
|
||||
@ -132,16 +142,19 @@ class AdminController extends Controller
|
||||
$file->move(public_path('uploads/products'), $fileName);
|
||||
$validated['picture'] = $fileName;
|
||||
}
|
||||
|
||||
$product->update($validated);
|
||||
|
||||
return redirect()->back()->with('success', 'Product Updated Successfully');
|
||||
}
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function deleteProduct($id)
|
||||
{
|
||||
if (session()->get('type') == 'Admin') {
|
||||
$product = Product::find($id);
|
||||
$product->delete();
|
||||
return redirect()->back()->with('success', 'Product Deleted Successfully');
|
||||
}
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ class MainController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if (session()->get('type') == 'Customer') {
|
||||
$allProducts = Products::all();
|
||||
//dd($allProducts);
|
||||
$newArrival = Products::where('type', 'new-arrival')->get();
|
||||
@ -28,6 +29,8 @@ class MainController extends Controller
|
||||
|
||||
return view('index', compact('allProducts', 'hotSale', 'newArrival'));
|
||||
}
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function about()
|
||||
{
|
||||
@ -82,19 +85,38 @@ class MainController extends Controller
|
||||
return view('login');
|
||||
}
|
||||
|
||||
// public function loginUser(Request $data)
|
||||
// {
|
||||
// $user = User::where('email', $data->input('email'))->first();
|
||||
// if ($user && Hash::check($data->input('password'), $user->password)) { // Verifying the hashed password
|
||||
// session()->put('id', $user->id);
|
||||
// session()->put('type', $user->type);
|
||||
// if ($user->type == 'Customer') {
|
||||
// return redirect('/');
|
||||
// }else if($user->type == 'Admin'){
|
||||
// return redirect('/admin)}
|
||||
// } else {
|
||||
// return redirect('login')->with('error', 'Invalid email or password!');
|
||||
// }
|
||||
// }
|
||||
|
||||
public function loginUser(Request $data)
|
||||
{
|
||||
$user = User::where('email', $data->input('email'))->first();
|
||||
if ($user && Hash::check($data->input('password'), $user->password)) { // Verifying the hashed password
|
||||
|
||||
if ($user && Hash::check($data->input('password'), $user->password)) {
|
||||
session()->put('id', $user->id);
|
||||
session()->put('type', $user->type);
|
||||
|
||||
if ($user->type == 'Customer') {
|
||||
return redirect('/');
|
||||
} else if ($user->type == 'Admin') {
|
||||
return redirect('/admin');
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
return redirect('login')->with('error', 'Invalid email or password!');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function logout()
|
||||
|
@ -8,8 +8,7 @@
|
||||
<div class="row">
|
||||
<div class="col-12 col-xl-8 mb-4 mb-xl-0">
|
||||
<h3 class="font-weight-bold">Welcome Aamir</h3>
|
||||
<h6 class="font-weight-normal mb-0">All systems are running smoothly! You have
|
||||
<span class="text-primary">3 unread alerts!</span>
|
||||
<h6 class="font-weight-normal mb-0">All systems are running smoothly!
|
||||
</h6>
|
||||
</div>
|
||||
<div class="col-12 col-xl-4">
|
||||
|
@ -15,7 +15,7 @@
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>Skydash Admin</title>
|
||||
<title> Admin Panel</title>
|
||||
<!-- plugins:css -->
|
||||
<link rel="stylesheet" href="Dashboard/vendors/feather/feather.css">
|
||||
<link rel="stylesheet" href="Dashboard/vendors/ti-icons/css/themify-icons.css">
|
||||
|
Loading…
Reference in New Issue
Block a user