"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,12 +10,18 @@ class AdminController extends Controller
|
|||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
return view('Dashboard.index');
|
if (session()->get('type') == 'Admin') {
|
||||||
|
return view('Dashboard.index');
|
||||||
|
}
|
||||||
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
public function products()
|
public function products()
|
||||||
{
|
{
|
||||||
$products = Product::all();
|
if (session()->get('type') == 'Admin') {
|
||||||
return view('Dashboard.products', compact('products'));
|
$products = Product::all();
|
||||||
|
return view('Dashboard.products', compact('products'));
|
||||||
|
}
|
||||||
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
// public function addNewProduct()
|
// public function addNewProduct()
|
||||||
// {
|
// {
|
||||||
@ -58,26 +64,29 @@ class AdminController extends Controller
|
|||||||
//mass assignment for adding new product
|
//mass assignment for adding new product
|
||||||
public function addNewProduct(Request $request)
|
public function addNewProduct(Request $request)
|
||||||
{
|
{
|
||||||
$validated = $request->validate([
|
if (session()->get('type') == 'Admin') {
|
||||||
'name' => 'required',
|
$validated = $request->validate([
|
||||||
'price' => 'required|numeric',
|
'name' => 'required',
|
||||||
'description' => 'required',
|
'price' => 'required|numeric',
|
||||||
'file' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
|
'description' => 'required',
|
||||||
'quantity' => 'required|numeric',
|
'file' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
|
||||||
'category' => 'required',
|
'quantity' => 'required|numeric',
|
||||||
'type' => 'required',
|
'category' => 'required',
|
||||||
]);
|
'type' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
if ($request->hasFile('file')) {
|
if ($request->hasFile('file')) {
|
||||||
$file = $request->file('file');
|
$file = $request->file('file');
|
||||||
$fileName = time() . '_' . $file->getClientOriginalName();
|
$fileName = time() . '_' . $file->getClientOriginalName();
|
||||||
$file->move(public_path('uploads/products'), $fileName);
|
$file->move(public_path('uploads/products'), $fileName);
|
||||||
$validated['picture'] = $fileName;
|
$validated['picture'] = $fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
Product::create($validated);
|
||||||
|
|
||||||
|
return redirect()->back()->with('success', 'Product Added Successfully');
|
||||||
}
|
}
|
||||||
|
return redirect()->back();
|
||||||
Product::create($validated);
|
|
||||||
|
|
||||||
return redirect()->back()->with('success', 'Product Added Successfully');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -114,34 +123,38 @@ class AdminController extends Controller
|
|||||||
//mass assignment for update
|
//mass assignment for update
|
||||||
public function updateProduct(Request $request)
|
public function updateProduct(Request $request)
|
||||||
{
|
{
|
||||||
$validated = $request->validate([
|
if (session()->get('type') == 'Admin') {
|
||||||
'name' => 'required',
|
$validated = $request->validate([
|
||||||
'price' => 'required|numeric',
|
'name' => 'required',
|
||||||
'description' => 'required',
|
'price' => 'required|numeric',
|
||||||
'quantity' => 'required|numeric',
|
'description' => 'required',
|
||||||
'category' => 'required',
|
'quantity' => 'required|numeric',
|
||||||
'type' => 'required',
|
'category' => 'required',
|
||||||
'file' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
|
'type' => 'required',
|
||||||
]);
|
'file' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
|
||||||
|
]);
|
||||||
|
|
||||||
$product = Product::find($request->input('id'));
|
$product = Product::find($request->input('id'));
|
||||||
|
|
||||||
if ($request->hasFile('file')) {
|
if ($request->hasFile('file')) {
|
||||||
$file = $request->file('file');
|
$file = $request->file('file');
|
||||||
$fileName = time() . '_' . $file->getClientOriginalName();
|
$fileName = time() . '_' . $file->getClientOriginalName();
|
||||||
$file->move(public_path('uploads/products'), $fileName);
|
$file->move(public_path('uploads/products'), $fileName);
|
||||||
$validated['picture'] = $fileName;
|
$validated['picture'] = $fileName;
|
||||||
|
}
|
||||||
|
$product->update($validated);
|
||||||
|
return redirect()->back()->with('success', 'Product Updated Successfully');
|
||||||
}
|
}
|
||||||
|
return redirect()->back();
|
||||||
$product->update($validated);
|
|
||||||
|
|
||||||
return redirect()->back()->with('success', 'Product Updated Successfully');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteProduct($id)
|
public function deleteProduct($id)
|
||||||
{
|
{
|
||||||
$product = Product::find($id);
|
if (session()->get('type') == 'Admin') {
|
||||||
$product->delete();
|
$product = Product::find($id);
|
||||||
return redirect()->back()->with('success', 'Product Deleted Successfully');
|
$product->delete();
|
||||||
|
return redirect()->back()->with('success', 'Product Deleted Successfully');
|
||||||
|
}
|
||||||
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,13 +20,16 @@ class MainController extends Controller
|
|||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$allProducts = Products::all();
|
if (session()->get('type') == 'Customer') {
|
||||||
//dd($allProducts);
|
$allProducts = Products::all();
|
||||||
$newArrival = Products::where('type', 'new-arrival')->get();
|
//dd($allProducts);
|
||||||
$hotSale = Products::where('type', 'sale')->get();
|
$newArrival = Products::where('type', 'new-arrival')->get();
|
||||||
|
$hotSale = Products::where('type', 'sale')->get();
|
||||||
|
|
||||||
|
|
||||||
return view('index', compact('allProducts', 'hotSale', 'newArrival'));
|
return view('index', compact('allProducts', 'hotSale', 'newArrival'));
|
||||||
|
}
|
||||||
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function about()
|
public function about()
|
||||||
@ -82,18 +85,37 @@ class MainController extends Controller
|
|||||||
return view('login');
|
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)
|
public function loginUser(Request $data)
|
||||||
{
|
{
|
||||||
$user = User::where('email', $data->input('email'))->first();
|
$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('id', $user->id);
|
||||||
session()->put('type', $user->type);
|
session()->put('type', $user->type);
|
||||||
|
|
||||||
if ($user->type == 'Customer') {
|
if ($user->type == 'Customer') {
|
||||||
return redirect('/');
|
return redirect('/');
|
||||||
|
} else if ($user->type == 'Admin') {
|
||||||
|
return redirect('/admin');
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return redirect('login')->with('error', 'Invalid email or password!');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return redirect('login')->with('error', 'Invalid email or password!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,8 +8,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12 col-xl-8 mb-4 mb-xl-0">
|
<div class="col-12 col-xl-8 mb-4 mb-xl-0">
|
||||||
<h3 class="font-weight-bold">Welcome Aamir</h3>
|
<h3 class="font-weight-bold">Welcome Aamir</h3>
|
||||||
<h6 class="font-weight-normal mb-0">All systems are running smoothly! You have
|
<h6 class="font-weight-normal mb-0">All systems are running smoothly!
|
||||||
<span class="text-primary">3 unread alerts!</span>
|
|
||||||
</h6>
|
</h6>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12 col-xl-4">
|
<div class="col-12 col-xl-4">
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<!-- Required meta tags -->
|
<!-- Required meta tags -->
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
<title>Skydash Admin</title>
|
<title> Admin Panel</title>
|
||||||
<!-- plugins:css -->
|
<!-- plugins:css -->
|
||||||
<link rel="stylesheet" href="Dashboard/vendors/feather/feather.css">
|
<link rel="stylesheet" href="Dashboard/vendors/feather/feather.css">
|
||||||
<link rel="stylesheet" href="Dashboard/vendors/ti-icons/css/themify-icons.css">
|
<link rel="stylesheet" href="Dashboard/vendors/ti-icons/css/themify-icons.css">
|
||||||
|
Loading…
Reference in New Issue
Block a user