diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php
index 95c8966..66bea7f 100644
--- a/app/Http/Controllers/AdminController.php
+++ b/app/Http/Controllers/AdminController.php
@@ -2,8 +2,10 @@
namespace App\Http\Controllers;
+use Illuminate\Support\Facades\URL;
use App\Models\User;
+
use Illuminate\Http\Request;
use App\Models\Product;
@@ -169,4 +171,24 @@ class AdminController extends Controller
}
return redirect()->back();
}
+
+ public function customers()
+ {
+ if (session()->get('type') == 'Admin') {
+ $customers = User::where('type', 'customer')->get();
+ return view('Dashboard.customers', compact('customers'));
+ }
+ return redirect()->back();
+ }
+
+ public function changeUserStatus($status, $id)
+ {
+ if (session()->get('type') == 'Admin') {
+ $user = User::find($id);
+ $user->status = $status;
+ $user->save();
+ return redirect()->back()->with('success', 'User Status Changed Successfully');
+ }
+ return redirect()->back();
+ }
}
diff --git a/app/Http/Controllers/MainController.php b/app/Http/Controllers/MainController.php
index d4a312c..c8f41b4 100644
--- a/app/Http/Controllers/MainController.php
+++ b/app/Http/Controllers/MainController.php
@@ -100,18 +100,44 @@ class MainController extends Controller
// }
// }
+
+ //old loginUser
+ // public function loginUser(Request $data)
+ // {
+ // $user = User::where('email', $data->input('email'))->first();
+
+ // //if ($user && Hash::check($data->input('password'), $user->password)) {
+ // if ($user && Hash::check($data->input('password'), $user->password) && $user->status == 'Active') {
+ // session()->put('id', $user->id);
+ // session()->put('type', $user->type);
+
+ // if ($user->type == 'Customer') {
+ // return redirect('/');
+ // } else if ($user->type == 'Admin') {
+ // return redirect('/admin');
+ // }
+ // }
+
+ // return redirect('login')->with('error', 'Invalid email or password!');
+ // }
+
+ //new loginUser
public function loginUser(Request $data)
{
$user = User::where('email', $data->input('email'))->first();
if ($user && Hash::check($data->input('password'), $user->password)) {
- session()->put('id', $user->id);
- session()->put('type', $user->type);
+ if ($user->status == 'Active') {
+ session()->put('id', $user->id);
+ session()->put('type', $user->type);
- if ($user->type == 'Customer') {
- return redirect('/');
- } else if ($user->type == 'Admin') {
- return redirect('/admin');
+ if ($user->type == 'Customer') {
+ return redirect('/');
+ } elseif ($user->type == 'Admin') {
+ return redirect('/admin');
+ }
+ } elseif ($user->status == 'Blocked') {
+ return redirect('login')->with('error', 'Your account is blocked. Please contact support.');
}
}
@@ -214,21 +240,6 @@ class MainController extends Controller
}
- // public function myOrders()
- // {
- // if (session()->has('id')) {
- // $orders = Order::where('customerId', session()->get('id'))->get();
- // // dd($orders);
- // $items = DB::table('products')
- // ->join('order_items', 'order_items.productId', '=', 'products.id')
- // ->select('products.name', 'products.picture', 'products.*')
- // ->get();
-
- // return view('orders', compact('orders', 'items'));
- // }
-
- // return view('login');
- // }
//old myOrders
// public function myOrders()
@@ -250,19 +261,22 @@ class MainController extends Controller
//new myOrders
public function myOrders()
{
- if (session()->has('id')) {
- $orders = Order::where('customerId', session()->get('id'))->get();
+ if (session()->get('type') == 'Customer') {
+ if (session()->has('id')) {
+ $orders = Order::where('customerId', session()->get('id'))->get();
- $items = DB::table('products')
- ->join('order_items', 'order_items.productId', '=', 'products.id')
- ->select('products.name', 'products.picture', 'order_items.*')
+ $items = DB::table('products')
+ ->join('order_items', 'order_items.productId', '=', 'products.id')
+ ->select('products.name', 'products.picture', 'order_items.*')
- ->get();
+ ->get();
- return view('orders', compact('orders', 'items'));
+ return view('orders', compact('orders', 'items'));
+ }
+
+ return view('login');
}
-
- return view('login');
+ return redirect()->back();
}
diff --git a/database/migrations/2024_07_15_072456_add_column_status_to_users.php b/database/migrations/2024_07_15_072456_add_column_status_to_users.php
new file mode 100644
index 0000000..9f4611c
--- /dev/null
+++ b/database/migrations/2024_07_15_072456_add_column_status_to_users.php
@@ -0,0 +1,29 @@
+string('status')->default('Active');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('users', function (Blueprint $table) {
+ //
+ });
+ }
+};
diff --git a/public/uploads/profiles/team-4.jpg b/public/uploads/profiles/team-4.jpg
new file mode 100644
index 0000000..94aed61
Binary files /dev/null and b/public/uploads/profiles/team-4.jpg differ
diff --git a/resources/views/Dashboard/customers.blade.php b/resources/views/Dashboard/customers.blade.php
new file mode 100644
index 0000000..3ae7615
--- /dev/null
+++ b/resources/views/Dashboard/customers.blade.php
@@ -0,0 +1,104 @@
+
+
+
+
+
+
+
+
+
+
Welcome Aamir
+ All systems are running smoothly!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Our Customers
+
+ @php
+ use Illuminate\Support\Facades\URL;
+ @endphp
+
+
+
+ ID |
+ Name |
+ Picture |
+ Email |
+ Type |
+ Created At |
+ Status |
+ Actions |
+
+
+
+
+ @php
+ $i = 0;
+ @endphp
+ @foreach ($customers as $customer)
+ @php
+ $i++;
+ @endphp
+
+ {{ $i }} |
+ {{ $customer->name }} |
+ |
+ {{ $customer->email }} |
+ {{ $customer->type }} |
+ {{ $customer->created_at }} |
+ {{ $customer->status }} |
+
+ @if ($customer->status == 'Active')
+ Block
+ @else
+ Active
+ @endif
+ |
+ @endforeach
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/resources/views/components/adminheader.blade.php b/resources/views/components/adminheader.blade.php
index ff4092b..336a5e1 100644
--- a/resources/views/components/adminheader.blade.php
+++ b/resources/views/components/adminheader.blade.php
@@ -375,7 +375,7 @@
diff --git a/resources/views/orders.blade.php b/resources/views/orders.blade.php
index 5048a2c..491499f 100644
--- a/resources/views/orders.blade.php
+++ b/resources/views/orders.blade.php
@@ -17,7 +17,6 @@
S.No. |
Name |
Address |
- {{--
Description | --}}
Phone |
Status |
Order Date |
@@ -38,7 +37,6 @@
{{ $i }} |
{{ $item->name }} |
{{ $item->address }} |
- {{--
{{ $item->description }} | --}}
{{ $item->phone }} |
{{ $item->status }} |
{{ $item->created_at }} |
@@ -116,9 +114,6 @@
@endforeach
-
-
-
@@ -130,9 +125,7 @@
|
-
-