Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some tips when you are creating methods and controllers :) greetings #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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();

Expand Down