A store has many products
ist die Beziehung.Route Modell Bindung in Beziehungen
So erstellen Sie ein neues Produkt, speichern store_id und andere Produktdetails.
Der Code wie folgt.
Strecke ist
Route::resource('stores.product', 'productcontroller');
d.h. Bindungsmodellspeicher mit Produkt Route.
Modell Store
class store extends Model
{
public function product()
{
return $this->hasMany(product::class);
}
}
create product
Ansicht.
<form method="POST" action="/stores/{{$store->id}}/product" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="form-group">
name <input type="text" name="name" />
</div>
public function store (store $store, Request $request)
{
$this->validate($request, [
'name' => 'required|max:255',
'detail' => 'nullable' ,
]);
$product = new product;
$product-> user_id = auth()->id();
$product-> store_id = $store->id;
$product-> name = $request->name;
$product->save();
return redirect('/stores/{{$store->id}}/product');
}
Bitte erläutern Sie, wie Route Modell funktioniert in Beziehungen zu binden.
Was sollte die Methode und die Aktion meiner Erstellungsform sein?
Wo sollte [email protected]
Return Redirect?