diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 95b120f..cbc9717 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -3,11 +3,78 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use App\Models\Product; + class AdminController extends Controller { - public function admin() + public function index() { return view('Dashboard.index'); } + public function products() + { + $products = Product::all(); + return view('Dashboard.products', compact('products')); + } + // public function addNewProduct() + // { + // $validated = request()->validate([ + // 'name' => 'required', + // 'price' => 'required', + // 'description' => 'required', + // 'image' => 'required|image|mimes:jpeg,png,jpg,gif, + // svg|max:2048', + // 'quantity' => 'required', + + + // ]); + + // if (request()->hasFile('file')) { + // $file = request()->file('file'); + // $fileName = $file->getClientOriginalName(); + // $file->move('uploads/products/', $fileName); + // request()->merge([ + // 'picture' => $fileName, + // ]); + // } + // Product::create(request()->all()); + // // $product = new Product(); + // // $product->name = $data->input('name'); + // // $product->picture = $data->file('file')->getClientOriginalName(); + // // $data->file('file')->move('uploads/products/', $product->picture); + // // $product->description = $data->input('description'); + // // $product->price = $data->input('price'); + // // $product->quantity = $data->input('quantity'); + // // $product->category = $data->input('category'); + // // $product->type = $data->input('type'); + + // // $abc = $product->save(); + // // dd($abc); + // return redirect()->back()->with('success', 'Product Added Successfully'); + // // return view('Dashboard.addNewProduct'); + // } + public function addNewProduct(Request $request) + { + $validated = $request->validate([ + 'name' => 'required', + 'price' => 'required|numeric', + 'description' => 'required', + 'file' => 'required|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::create($validated); + + return redirect()->back()->with('success', 'Product Added Successfully'); + } } diff --git a/app/Models/Product.php b/app/Models/Product.php new file mode 100644 index 0000000..46416bc --- /dev/null +++ b/app/Models/Product.php @@ -0,0 +1,20 @@ + + + +
+
+
+
+
+
+

Welcome Aamir

+
All systems are running smoothly! You have + 3 unread alerts! +
+
+
+
+ +
+
+
+
+
+ + + +
+
+
+
+ + + + + +

Top Products

+
+ + + + + + + {{-- --}} + + + + + + + + + + @foreach ($products as $item) + + + + + {{-- --}} + + {{-- --}} + + + + + @endforeach + + + + +
IDNamePictureDescriptionPriceQuantityCategoryTypeActions
{{ $item->id }}{{ $item->name }} {{ $item->description }}Nrs.{{ $item->price }}{{ $item->quantity }}{{ $item->category }}{{ $item->type }}
+
+
+
+
+ +
+ +
+ + + diff --git a/resources/views/components/adminfooter.blade.php b/resources/views/components/adminfooter.blade.php index 4fb910e..e5d7ec0 100644 --- a/resources/views/components/adminfooter.blade.php +++ b/resources/views/components/adminfooter.blade.php @@ -43,4 +43,47 @@ + {{-- --}} + diff --git a/resources/views/components/adminheader.blade.php b/resources/views/components/adminheader.blade.php index ea475dd..4286c43 100644 --- a/resources/views/components/adminheader.blade.php +++ b/resources/views/components/adminheader.blade.php @@ -2,6 +2,16 @@ + {{-- + + + + + + + --}} + + @@ -27,7 +37,7 @@ diff --git a/routes/web.php b/routes/web.php index 229cb52..e7b8491 100644 --- a/routes/web.php +++ b/routes/web.php @@ -11,6 +11,8 @@ use Illuminate\Support\Facades\Route; //admin routes Route::get('/admin', [AdminController::class, 'index'])->name('admin'); +Route::get('/adminProducts', [AdminController::class, 'products'])->name('products'); +Route::post('/addNewProduct', [AdminController::class, 'addNewProduct'])->name('addNewProduct');