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
보기.
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');
}
<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>
는 경로 모델의 관계에서 작품을 바인딩하는 방법을 설명하십시오.
양식 작성 방법 및 조치는 무엇이되어야합니까?
어디에서 [email protected]
리디렉션해야합니까? 그에서
public function create(){
$storList = Store::all();
return view("createproductview", compact("storList"));
}
: 당신이 만드는 제품 페이지에 모든 상점을 통과해야
class Store extends Model
{
public function products()
{
return $this->hasMany(Product::class);
}
}
class Product extends Model
{
public function store()
{
return $this->belonsTo(Store::class);
}
}
둘째 :