diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index cbc9717..1e57f9c 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -54,6 +54,8 @@ class AdminController extends Controller // return redirect()->back()->with('success', 'Product Added Successfully'); // // return view('Dashboard.addNewProduct'); // } + + //mass assignment for adding new product public function addNewProduct(Request $request) { $validated = $request->validate([ @@ -77,4 +79,69 @@ class AdminController extends Controller return redirect()->back()->with('success', 'Product Added Successfully'); } + + + //normal assignment for update + // public function updateProduct(Request $request) + // { + // $validated = $request->validate([ + // 'name' => 'required', + // 'price' => 'required|numeric', + // 'description' => 'required', + // 'file' => 'image|mimes:jpeg,png,jpg,gif,svg|max + // :2048', + // 'quantity' => 'required|numeric', + // 'category' => 'required', + // 'type' => 'required', + // ]); + // if ($request->hasFile('file')) { + // $file = $request->file('file'); + // $fileName = time() . '_' . $file->getClientOriginalName(); + // $file->move(public_path('uploads/products'), $fileName); + // $validated['picture'] = $fileName; + // } + // $product = Product::find($request->id); + // $product->name = $validated['name']; + // $product->price = $validated['price']; + // $product->description = $validated['description']; + // $product->quantity = $validated['quantity']; + // $product->category = $validated['category']; + // $product->type = $validated['type']; + // $product->save(); + // return redirect()->back()->with('success', 'Product Updated Successfully'); + // } + + //mass assignment for update + public function updateProduct(Request $request) + { + $validated = $request->validate([ + 'name' => 'required', + 'price' => 'required|numeric', + 'description' => 'required', + 'quantity' => 'required|numeric', + 'category' => 'required', + 'type' => 'required', + 'file' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg|max:2048', + ]); + + $product = Product::find($request->input('id')); + + if ($request->hasFile('file')) { + $file = $request->file('file'); + $fileName = time() . '_' . $file->getClientOriginalName(); + $file->move(public_path('uploads/products'), $fileName); + $validated['picture'] = $fileName; + } + + $product->update($validated); + + return redirect()->back()->with('success', 'Product Updated Successfully'); + } + + public function deleteProduct($id) + { + $product = Product::find($id); + $product->delete(); + return redirect()->back()->with('success', 'Product Deleted Successfully'); + } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 452e6b6..7b03763 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -3,7 +3,7 @@ namespace App\Providers; use Illuminate\Support\ServiceProvider; - +use Illuminate\Pagination\Paginator; //add this too class AppServiceProvider extends ServiceProvider { /** @@ -19,6 +19,6 @@ class AppServiceProvider extends ServiceProvider */ public function boot(): void { - // + // Paginator::useBootstrap(); //this is the bootstrap code } } diff --git a/public/uploads/products/1720938545_wallpaperflare.com_wallpaper (7).jpg b/public/uploads/products/1720938545_wallpaperflare.com_wallpaper (7).jpg new file mode 100644 index 0000000..12ec53b Binary files /dev/null and b/public/uploads/products/1720938545_wallpaperflare.com_wallpaper (7).jpg differ diff --git a/public/uploads/products/1720938581_wallpaperflare.com_wallpaper (2).jpg b/public/uploads/products/1720938581_wallpaperflare.com_wallpaper (2).jpg new file mode 100644 index 0000000..0efe3ab Binary files /dev/null and b/public/uploads/products/1720938581_wallpaperflare.com_wallpaper (2).jpg differ diff --git a/public/uploads/products/1720938611_wallpaperflare.com_wallpaper (8).jpg b/public/uploads/products/1720938611_wallpaperflare.com_wallpaper (8).jpg new file mode 100644 index 0000000..de60926 Binary files /dev/null and b/public/uploads/products/1720938611_wallpaperflare.com_wallpaper (8).jpg differ diff --git a/resources/views/Dashboard/products.blade.php b/resources/views/Dashboard/products.blade.php index b0c41bd..9b169c4 100644 --- a/resources/views/Dashboard/products.blade.php +++ b/resources/views/Dashboard/products.blade.php @@ -57,148 +57,6 @@