Skip to content

Commit

Permalink
admin product controller successfully tested in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
oshkoshbagoshh committed Dec 20, 2023
1 parent 2b36b0a commit 6a84d00
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
29 changes: 28 additions & 1 deletion app/Http/Controllers/Admin/AdminProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,34 @@ public function index() {
return view("admin.product.index")->with("viewData", $viewData);
}




public function store(Request $request) {
$request->validate([
"name" => "required|max:255",
"description" => "required",
"price" => "required|numeric|gt:0",
"image" => 'image',

]);


// new products
$newProduct = new Product();
$newProduct -> setName($request->input('name'));
$newProduct -> setDescription($request->input('description'));
$newProduct -> setPrice($request->input('price'));
$newProduct -> setImage("game.png");
$newProduct -> save();

return back();




// ==========================
}
// ==========================
}


Expand Down
9 changes: 8 additions & 1 deletion zzAJ/notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ Chapter 16 - List Products in Admin Panel
Chapter 17 - Create Products

- focus on the admin panel system to create products
-/admin/products/store route will collect and store the newly created products data using a post HTTP request using a form with the controller method
- /admin/products/store route will collect and store the newly created products data using a post HTTP request using a form with the controller method
- in the AdminProductController.php file we create use a store function to receive a $request object which allows us to interact with the HTTP requeast handled by our app. This allows us to receive the inputs, cookies, and files from the request
- then we use the validate method provided by the $request object. If the validation rules pass it keeps going, otherwise it will throw an Exception
- TODO: check out the available validation rules in the docs
- then we create a newProduct instance and set the newProduct attributes based on values collected from the form.
- then, we invoke the save method, which inserts the object into the database
- NOTE: you can also use the HTML required attribute on the form for fields you need, but we don't need that since we're using Laravel's validations



0 comments on commit 6a84d00

Please sign in to comment.