我想传递$ id来创建控制器:
<div class="col-lg-2">
{!! Form::open(['route' => ['addkeluarga_form', id]]) !!}
{{ Form::submit('Add New', ['class' => 'btn btn-primary']) }}
{!! Form::close() !!}
</div>
我尝试将上面的代码替换为此,但是也失败了:
<form method="POST" action="{{ route('addkeluarga_form', $id) }}" accept-charset="UTF-8">
<input name="_method" type="hidden" value="POST">
{{ csrf_field() }}
<button type="submit" class="btn btn-sm btn-default">Add!</button>'
<input type="hidden" value="StaffKeluarga" />
</form>
这是控制器:
public function create(Request $request)
{
$idFromFrontEnd = $request->StaffKeluarga;
$staffs=DB::select("SELECT id FROM staffs WHERE id = ?", [$idFromFrontEnd]);
return view('keluarga.add_keluarga', compact('staffs', 'idFromFrontEnd'));
}
它可以查看刀片,但是$ idFromFrontEnd的值为null。 为什么不起作用?
答案 0 :(得分:0)
public function create(Request $request)
{
$idFromFrontEnd = $request->fromForm;
$staffs=DB::select("SELECT id FROM staffs WHERE id = ?", [$idFromFrontEnd]);