【发布时间】:2020-01-22 04:12:07
【问题描述】:
在我的项目中,希望从数据库中获取患者姓名并使用所选患者 ID 将新行插入到另一个表中。
耐心.blade.php
<form action="{{ route('secondvisit.store')}}" method="post" >
{{csrf_field()}}
<select name="ppid" id="select1" style="width: 200px" >
@foreach(\App\patient::all() as $pname)
<option value="{{$pname->pid}}">{{$pname->fname}} {{$pname->mname}} {{$pname->lname}} </option>
@endforeach
</select>
</form>
在 PatientController.php 中
public function store(Request $request)
{
$ob=new SecondVisit();
$ob->pid=$request->input('ppid'); //tested by get('ppid')
$ob->vagbl=$request->input('vagbl');
$ob->save();
return redirect(route('secondvisit.index'));
}
当点击保存按钮时,下面的异常会提示 pid 为空
Integrity constraint violation: 1048 Column 'pid' cannot be null
【问题讨论】:
-
您能否检查
pid列值。如果$pname->pid可能为空
标签: php mysql laravel laravel-blade