"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:
parent
f214f8aab4
commit
f171e49b3f
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -158,16 +158,19 @@ class MainController extends Controller
|
||||
|
||||
public function cart()
|
||||
{
|
||||
$cartItems = DB::table('products')
|
||||
// ->join('carts', 'carts.productId', '=', 'products.id')
|
||||
->join('carts', 'carts.productId', 'products.id')
|
||||
->select('products.name', 'products.price', 'products.picture', 'products.quantity as pQuantity', 'carts.*')
|
||||
->where('carts.customerId', session()->get('id'))
|
||||
->get();
|
||||
if (session()->get('type') == 'Customer') {
|
||||
$cartItems = DB::table('products')
|
||||
// ->join('carts', 'carts.productId', '=', 'products.id')
|
||||
->join('carts', 'carts.productId', 'products.id')
|
||||
->select('products.name', 'products.price', 'products.picture', 'products.quantity as pQuantity', 'carts.*')
|
||||
->where('carts.customerId', session()->get('id'))
|
||||
->get();
|
||||
|
||||
//dd($cartItems);
|
||||
//dd($cartItems);
|
||||
|
||||
return view('cart', compact('cartItems'));
|
||||
return view('cart', compact('cartItems'));
|
||||
}
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function addToCart(Request $data)
|
||||
@ -231,11 +234,14 @@ class MainController extends Controller
|
||||
|
||||
public function profile()
|
||||
{
|
||||
if (session()->has('id')) {
|
||||
$user = User::find(session()->get('id'));
|
||||
return view('profile', compact('user'));
|
||||
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('login');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function updateUser(Request $data)
|
||||
@ -290,22 +296,23 @@ class MainController extends Controller
|
||||
|
||||
public function testMail()
|
||||
{
|
||||
$details = [
|
||||
'title' => 'Mail from Uron Shrestha',
|
||||
'message' => 'This is for testing mail using smtp in Laravel!'
|
||||
];
|
||||
Mail::to("yuron.stha57@gmail.com")->send(new Testing($details));
|
||||
return redirect('/');
|
||||
if (session()->get('type') == 'Customer') {
|
||||
$details = [
|
||||
'title' => 'Mail from Uron Shrestha',
|
||||
'message' => 'This is for testing mail using smtp in Laravel!'
|
||||
];
|
||||
Mail::to("yuron.stha57@gmail.com")->send(new Testing($details));
|
||||
return redirect('/');
|
||||
}
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
||||
public function shop()
|
||||
{
|
||||
return view('shop');
|
||||
}
|
||||
|
||||
public function shopDetails()
|
||||
{
|
||||
return view('shopDetails');
|
||||
if (session()->get('type') == 'Customer') {
|
||||
return view('shop');
|
||||
}
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
BIN
public/uploads/products/1720951132_team-3.jpg
Normal file
BIN
public/uploads/products/1720951132_team-3.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
BIN
public/uploads/profiles/team-1.jpg
Normal file
BIN
public/uploads/profiles/team-1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
71
resources/views/Dashboard/profile.blade.php
Normal file
71
resources/views/Dashboard/profile.blade.php
Normal 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 />
|
@ -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>
|
||||
|
@ -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');
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user