From d01b8045e744d862b8b274c92f5863350027f9aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gilberto=20M=C3=A9ndez=20S?= Date: Fri, 24 Aug 2018 20:02:16 -0500 Subject: [PATCH] Some tips when you are creating methods and controllers :) greetings --- app/Http/Controllers/ProductController.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index f7e40f5..252f944 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -5,7 +5,8 @@ use App\Http\Requests\ProductRequest; use Illuminate\Http\Request; - +//tip : you can create a controler resource directly from the console, use this command : +//php artisan make:controller --resource, with this, you'll avoid to write the methods to make a crud, and will be genrated with comments class ProductController extends Controller { public function index() @@ -21,9 +22,10 @@ public function show($id) return view('products.show',compact('product')); } - public function destroy($id) + public function destroy(Product $product)// <- check this new way to access the resource { - + // NOTE : you can easily use 'model binding' + //$product->delete();// you can access to the resource directly, without the findOrFail static method :), greetings jaja $product = Product::findOrFail($id); $product->delete();