我尝试从列名表1到表2输入一个值。它出现了,但第一行的值是0。它收到错误消息。
控制器:
public function create()
{
$kelas_theresia = Kelas_Theresia::pluck('name')->all();
return view('kamar_theresia.create',compact('kamar_theresia','kelas_theresia'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
request()->validate([
'nama' => 'required|unique:kamar_theresia,nama',
'idkelas' => 'required',
'ketersediaan' => 'required',
]);
$input = $request->all();
$kamar_theresia = Kamar_Theresia::create($input);
return redirect()->route('kamar_theresia.index')
->with('success','Kamar Theresia created successfully.');
}
查看
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Kelas:</strong>
{!! Form::select('idkelas', $kelas_theresia,[], array('class' => 'form-control')) !!}
</div>
</div>
答案 0 :(得分:1)
在create
函数中,更改检索资源的行以包含id
。
因此,请添加它:
$kelas_theresia = Kelas_Theresia::pluck('name', 'id')->all();
因此这将使用正确的商品ID,并且在您存储时将是正确的ID,因为现在您的值就是名称。