【发布时间】:2020-08-13 11:55:47
【问题描述】:
病人控制者:
public function store(Request $request)
{
$input = request()->all();
Patient::create($input);
dd($input->id);
// return redirect()->route('medical.create',compact('input'));
}
这是我的 medical.create 视图
{!! Form::model($input, [
'method' => 'POST',
'action' => ['MedicalController@store', $input->id]
]) !!}
<div class="row">
<div class="col-md-4">
<div class="form-group">
{{Form::label('patient_id','Patient no:')}}
{{Form::text('patient_id', null, array('class' => 'form-control') )}}
</div>
</div>
</div>
{!! Form::close() !!}
我想在存储后获取我最后插入的 id,并在下一个表单中显示最后一个 id,但这是我屏幕上出现的错误:
Trying to get property 'id' of non-object
这是我的患者表:
【问题讨论】:
-
$患者 = Patient::create($input); dd($患者->id);
-
但这是创建 Trying to get property 'id' of non-object 后的错误
-
首先只打印 $patient 并查看包含的 id 吗?
-
是的,没有 id 我将代码更改为 dd($input)
-
array:12 [▼ "_token" => "BVFdC1JCfL55mYfRSIXzd3nKXF0clzknZrBoXWRC" "firstname" => "SAD" "middlename" => "SADAAA" "lastname" => "SADSA" "email" => "SA@GMAIL.COM" "联系人" => "asdsa" ]