我想通过从组合框中选择供应商的名称来插入供应商的ID。
查看
<label for="supplier">Supplier</label>
<input list="supplier" name="supplier" placeholder="Select Supplier" class="form-control">
@foreach($suppliers as $key=>$value)
<datalist id="supplier">
<option value="{{$key}}">{{$value}}
</datalist>
@endforeach
控制器
<?php
public function store(Request $request, User $user)
{
$user = Auth::user();
$product = new Product;
$request->user()->products()->create($request->all());
}
模型
protected $fillable = ['name', 'qty', 'bprice', 'sprice', 'edate'];
public function user()
{
return $this->belongsTo(User::class, user_id);
}
答案 0 :(得分:0)
使用此
public function store(Request $request, User $user)
{
$user = Auth::user();
$product = new Product;
$product->supplier_id = $request->supplier;
$product->price = $request->price; // if u hv it
。 //完成剩下的工作
$user->products()->save($product);
// finish the rest
}