"Updated AdminController, MainController, and adminheader.blade.php to add admin profile feature and modified cart and profile logic for customers"

This commit is contained in:
UronShrestha 2024-07-14 16:45:49 +05:45
parent f214f8aab4
commit f171e49b3f
7 changed files with 117 additions and 26 deletions

View File

@ -2,6 +2,8 @@
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use App\Models\Product;
@ -15,6 +17,7 @@ class AdminController extends Controller
}
return redirect()->back();
}
public function products()
{
if (session()->get('type') == 'Admin') {
@ -69,7 +72,7 @@ class AdminController extends Controller
'name' => 'required',
'price' => 'required|numeric',
'description' => 'required',
'file' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
'file' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:10240',
'quantity' => 'required|numeric',
'category' => 'required',
'type' => 'required',
@ -157,4 +160,13 @@ class AdminController extends Controller
}
return redirect()->back();
}
public function profile()
{
if (session()->get('type') == 'Admin') {
$user = User::find(session()->get('id'));
return view('Dashboard.profile', compact('user'));
}
return redirect()->back();
}
}

View File

@ -158,6 +158,7 @@ class MainController extends Controller
public function cart()
{
if (session()->get('type') == 'Customer') {
$cartItems = DB::table('products')
// ->join('carts', 'carts.productId', '=', 'products.id')
->join('carts', 'carts.productId', 'products.id')
@ -169,6 +170,8 @@ class MainController extends Controller
return view('cart', compact('cartItems'));
}
return redirect()->back();
}
public function addToCart(Request $data)
{
@ -231,12 +234,15 @@ class MainController extends Controller
public function profile()
{
if (session()->get('type') == 'Customer') {
if (session()->has('id')) {
$user = User::find(session()->get('id'));
return view('profile', compact('user'));
}
return redirect('login');
}
return redirect()->back();
}
public function updateUser(Request $data)
{
@ -290,6 +296,7 @@ class MainController extends Controller
public function testMail()
{
if (session()->get('type') == 'Customer') {
$details = [
'title' => 'Mail from Uron Shrestha',
'message' => 'This is for testing mail using smtp in Laravel!'
@ -297,15 +304,15 @@ class MainController extends Controller
Mail::to("yuron.stha57@gmail.com")->send(new Testing($details));
return redirect('/');
}
return redirect()->back();
}
public function shop()
{
if (session()->get('type') == 'Customer') {
return view('shop');
}
public function shopDetails()
{
return view('shopDetails');
return redirect()->back();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View File

@ -0,0 +1,71 @@
<x-adminheader />
<!-- partial -->
<div class="main-panel">
<div class="content-wrapper">
<div class="row">
<div class="col-12 mt-5 col-md-6 col-lg-4 mx-auto grid-margin stretch-card">
<div class="card">
<div class="card-body">
<p class="card-title mb-0">My Profile</p>
@if (session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif
@if (session('error'))
<div class="alert alert-danger">
{{ session('error') }}
</div>
@endif
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<img src="{{ 'uploads/profiles/' . $user->picture }}"
class=" mx-auto d-block mb-2 rounded-circle" alt="profile picture" width="100px"
height="100px">
<form action="{{ URL::to('updateUser') }}" method="POST" enctype="multipart/form-data">
@csrf
<div class="row">
<div class="col-lg-12">
<input type="text" name="name" value="{{ $user->name }}" id="name"
placeholder="Name" class="form-control mb-2" required>
</div>
<div class="col-lg-12">
<input type="email" name="email" value="{{ $user->email }}" id="email"
placeholder="Email" class="form-control mb-2" readonly required>
</div>
<div class="col-lg-12">
<input type="file" name="file" class="form-control mb-2">
</div>
<div class="col-lg-12">
<input type="password" name="password" value="{{ $user->password }}" id="password"
placeholder="Password" class="form-control mb-2">
</div>
<div class="col-lg-12 d-flex justify-content-center">
<button type="submit" class="btn btn-info ">Save Changes</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- content-wrapper ends -->
<x-adminfooter />

View File

@ -406,7 +406,7 @@
<ul class="nav flex-column sub-menu">
<li class="nav-item"> <a class="nav-link" href="{{ route('logout') }}"> Logout </a>
</li>
<li class="nav-item"> <a class="nav-link" href="#">
<li class="nav-item"> <a class="nav-link" href="{{ route('adminProfile') }}">
Profile </a></li>
</ul>
</div>

View File

@ -15,6 +15,7 @@ Route::get('/adminProducts', [AdminController::class, 'products'])->name('produc
Route::post('/addNewProduct', [AdminController::class, 'addNewProduct'])->name('addNewProduct');
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');