Added new admin features, updated login functionality, and modified orders view
This commit is contained in:
parent
d8e17eef70
commit
9c427917b8
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -100,19 +100,45 @@ 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)) {
|
||||
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') {
|
||||
} elseif ($user->type == 'Admin') {
|
||||
return redirect('/admin');
|
||||
}
|
||||
} elseif ($user->status == 'Blocked') {
|
||||
return redirect('login')->with('error', 'Your account is blocked. Please contact support.');
|
||||
}
|
||||
}
|
||||
|
||||
return redirect('login')->with('error', 'Invalid email or password!');
|
||||
@ -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,6 +261,7 @@ class MainController extends Controller
|
||||
//new myOrders
|
||||
public function myOrders()
|
||||
{
|
||||
if (session()->get('type') == 'Customer') {
|
||||
if (session()->has('id')) {
|
||||
$orders = Order::where('customerId', session()->get('id'))->get();
|
||||
|
||||
@ -264,6 +276,8 @@ class MainController extends Controller
|
||||
|
||||
return view('login');
|
||||
}
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
//
|
||||
$table->string('status')->default('Active');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
};
|
BIN
public/uploads/profiles/team-4.jpg
Normal file
BIN
public/uploads/profiles/team-4.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
104
resources/views/Dashboard/customers.blade.php
Normal file
104
resources/views/Dashboard/customers.blade.php
Normal file
@ -0,0 +1,104 @@
|
||||
<x-adminheader />
|
||||
|
||||
<!-- partial -->
|
||||
<div class="main-panel">
|
||||
<div class="content-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-md-12 grid-margin">
|
||||
<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!
|
||||
</h6>
|
||||
</div>
|
||||
<div class="col-12 col-xl-4">
|
||||
<div class="justify-content-end d-flex">
|
||||
<div class="dropdown flex-md-grow-1 flex-xl-grow-0">
|
||||
<button class="btn btn-sm btn-light bg-white dropdown-toggle" type="button"
|
||||
id="dropdownMenuDate2" data-toggle="dropdown" aria-haspopup="true"
|
||||
aria-expanded="true">
|
||||
<i class="mdi mdi-calendar"></i> Today (10 Jan 2021)
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuDate2">
|
||||
<a class="dropdown-item" href="#">January - March</a>
|
||||
<a class="dropdown-item" href="#">March - June</a>
|
||||
<a class="dropdown-item" href="#">June - August</a>
|
||||
<a class="dropdown-item" href="#">August - November</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12 grid-margin stretch-card">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
|
||||
|
||||
<p class="card-title mb-0">Our Customers</p>
|
||||
<div class="table-responsive">
|
||||
@php
|
||||
use Illuminate\Support\Facades\URL;
|
||||
@endphp
|
||||
<table class="table table-striped table-bordered" id="product-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Picture</th>
|
||||
<th>Email</th>
|
||||
<th>Type</th>
|
||||
<th>Created At</th>
|
||||
<th>Status</th>
|
||||
<th>Actions</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
$i = 0;
|
||||
@endphp
|
||||
@foreach ($customers as $customer)
|
||||
@php
|
||||
$i++;
|
||||
@endphp
|
||||
<tr>
|
||||
<td>{{ $i }}</td>
|
||||
<td>{{ $customer->name }}</td>
|
||||
<td><img src="{{ asset('uploads/profiles/' . $customer->picture) }}"
|
||||
alt="" class="img-fluid rounded mx-auto d-block"></td>
|
||||
<td>{{ $customer->email }}</td>
|
||||
<td>{{ $customer->type }}</td>
|
||||
<td>{{ $customer->created_at }}</td>
|
||||
<td>{{ $customer->status }}</td>
|
||||
<td>
|
||||
@if ($customer->status == 'Active')
|
||||
<a class="btn btn-danger"
|
||||
href="{{ url::to('changeUserStatus/Blocked', ['id' => $customer->id]) }}">Block</a>
|
||||
@else
|
||||
<a class="btn btn-success"
|
||||
href="{{ url::to('changeUserStatus/Active', ['id' => $customer->id]) }}">Active</a>
|
||||
@endif
|
||||
</td>
|
||||
@endforeach
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- content-wrapper ends -->
|
||||
|
||||
<x-adminfooter />
|
@ -375,7 +375,7 @@
|
||||
</a>
|
||||
<div class="collapse" id="form-elements">
|
||||
<ul class="nav flex-column sub-menu">
|
||||
<li class="nav-item"><a class="nav-link" href="#">View
|
||||
<li class="nav-item"><a class="nav-link" href="{{ route('ourCustomers') }}">View
|
||||
All</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -17,7 +17,6 @@
|
||||
<th>S.No.</th>
|
||||
<th>Name</th>
|
||||
<th>Address</th>
|
||||
{{-- <th>Description</th> --}}
|
||||
<th>Phone</th>
|
||||
<th>Status</th>
|
||||
<th>Order Date</th>
|
||||
@ -38,7 +37,6 @@
|
||||
<td>{{ $i }}</td>
|
||||
<td>{{ $item->name }}</td>
|
||||
<td>{{ $item->address }}</td>
|
||||
{{-- <td>{{ $item->description }}</td> --}}
|
||||
<td>{{ $item->phone }}</td>
|
||||
<td>{{ $item->status }}</td>
|
||||
<td>{{ $item->created_at }}</td>
|
||||
@ -116,9 +114,6 @@
|
||||
@endforeach
|
||||
|
||||
</tbody>
|
||||
|
||||
|
||||
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="4" style="text-align: center;">
|
||||
@ -130,9 +125,7 @@
|
||||
</tfoot>
|
||||
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Modal footer -->
|
||||
<div class="modal-footer">
|
||||
|
||||
|
@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Route;
|
||||
|
||||
|
||||
|
||||
|
||||
//admin routes
|
||||
Route::get('/admin', [AdminController::class, 'index'])->name('admin');
|
||||
Route::get('/adminProducts', [AdminController::class, 'products'])->name('products');
|
||||
@ -16,6 +17,8 @@ Route::post('/addNewProduct', [AdminController::class, 'addNewProduct'])->name('
|
||||
Route::post('/updateProduct', [AdminController::class, 'updateProduct'])->name('updateProduct');
|
||||
Route::get('/deleteProduct/{id}', [AdminController::class, 'deleteProduct'])->name('deleteProduct');
|
||||
Route::get('/adminProfile', [AdminController::class, 'profile'])->name('adminProfile');
|
||||
Route::get('/ourCustomers', [AdminController::class, 'customers'])->name('ourCustomers');
|
||||
Route::get('/changeUserStatus/{status}/{id}', [AdminController::class, 'changeUserStatus'])->name('changeUserStatus');
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user