0
store has many products
は関係です。関係のルートモデルバインド
新しい製品を作成する方法、store_idとその他の製品の詳細を保存する方法。
コードは次のとおりです。
ルート製品経路に
Route::resource('stores.product', 'productcontroller');
すなわち結合モデルストアです。
モデルStore
class store extends Model
{
public function product()
{
return $this->hasMany(product::class);
}
}
create product
ビュー。
<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');
}
ルートモデルは、関係で作品を結合する方法を説明してください。
作成フォームのメソッドとアクションはどのようなものでしょうか?
どこですか?[email protected]
リターンが返されますか?