【发布时间】:2018-07-07 13:21:41
【问题描述】:
我可以请求选中的并查看它们,但我不能更新它。
在数据库中,我有表 types 和类型 2 列:rijbewijsnummer, rijbewijstype
如何更新数据库中新检查的?
我的控制器中的功能
public function Modify (Request $request) {
$user = Auth::user();
$type = Type::all();
$user->rijbewijsnummer = Request::input('rijbewijsnummer');
$type->rijbewijstype = Request::input('rijbewijstype');
$user->save();
return redirect()->route('home');
}
我觉得我做错了什么
public function details(Request $request)
{
$user = Auth::user();
$types = Type::where("rijbewijsnummer", "=", $user->rijbewijsnummer)->get();
foreach ($types as $type)
{
$rijbewijstype[]= $type->rijbewijstype;
}
$user->save();
return view('details', compact('user','rijbewijstype', 'types'));
}
查看:
<div class="col-md-6">
<div name="rijbewijstype">
<input type="checkbox" name="rijbewijstype[]" @foreach ($types as $type) @if ($type->rijbewijstype == "AM")) checked @endif @endforeach value="AM" >AM</input>
<input type="checkbox" name="rijbewijstype[]" @foreach ($types as $type) @if ($type->rijbewijstype == "A1") checked @endif @endforeach value="A1">A1</input>
<input type="checkbox" name="rijbewijstype[]" @foreach ($types as $type) @if ($type->rijbewijstype == "A2") checked @endif @endforeach value="A2">A2</input>
<input type="checkbox" name="rijbewijstype[]" @foreach ($types as $type) @if ($type->rijbewijstype == "A") checked @endif @endforeach value="A">A</input>
<input type="checkbox" name="rijbewijstype[]" @foreach ($types as $type) @if ($type->rijbewijstype == "B1") checked @endif @endforeach value="B1">B1</input>
<input type="checkbox" name="rijbewijstype[]" @foreach ($types as $type) @if ($type->rijbewijstype == "B") checked @endif @endforeach value="B">B</input> <br>
<input type="checkbox" name="rijbewijstype[]" @foreach ($types as $type) @if ($type->rijbewijstype == "C1") checked @endif @endforeach value="C1">C1</input>
<input type="checkbox" name="rijbewijstype[]" @foreach ($types as $type) @if ($type->rijbewijstype == "D1") checked @endif @endforeach value="D1">D1</input>
<input type="checkbox" name="rijbewijstype[]" @foreach ($types as $type) @if($type->rijbewijstype == "D") checked @endif @endforeach value="D">D</input>
<input type="checkbox" name="rijbewijstype[]" @foreach ($types as $type) @if ($type->rijbewijstype == "BE") checked @endif @endforeach value="BE">BE</input>
<input type="checkbox" name="rijbewijstype[]" @foreach ($types as $type) @if ($type->rijbewijstype == "C1E") checked @endif @endforeach value="C1E">C1E</input>
<input type="checkbox" name="rijbewijstype[]" @foreach ($types as $type) @if ($type->rijbewijstype == "CE") checked @endif @endforeach value="CE">CE</input>
<input type="checkbox" name="rijbewijstype[]" @foreach ($types as $type) @if ($type->rijbewijstype == "D1E") checked @endif @endforeach value="D1E">D1E</input>
<input type="checkbox" name="rijbewijstype[]" @foreach ($types as $type) @if ($type->rijbewijstype == "DE") checked @endif @endforeach value="DE">DE</input>
<input type="checkbox" name="rijbewijstype[]" @foreach ($types as $type) @if ($type->rijbewijstype == "T") checked @endif @endforeach value="T">T</input>
</div>
</div>
【问题讨论】:
标签: php html arrays database laravel