"Updated AdminController, added products method and addNewProduct method, modified adminfooter and adminheader blade files, and added routes for admin products and add new product"
This commit is contained in:
@ -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');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user