CRUD işlemler için önce bir controller oluşturup, yapılacak işlem için method oluşturulması gerekir.
Bu methodları tek bir komutla oluşturmak için;
php artisan make:controller ProductController --resource --model=Product
Oluşturulan ProductController'daki örnek method;
public function show(Product $product) { }
Son parametre olan --model Product modeli belirtildiğinde Model Binding ile çağrılan methodda Product'ta tanımlı tüm değerlere ulaşır.
php artisan make:controller ProductController --resource
Oluşturulan ProductController'daki örnek method;
public function show($id) { }
web.php'de örnek kullanım;
Route::resource('/products', '\App\Http\Controllers\ProductController');
sadece belirli methodların kullanılmasını istiyorsanız;
->only(['index','show']) parametresini, belirli methodların kullanılmamasını istiyorsanız;
->except(['destroy']) parametresini kullanabilirsiniz.
API'lar için;
php artisan make:model Product -c -m -r ile model, migration, resource controller üçü bir arada eklenir.