我正在尝试访问在 url 中传递的变量以传递给新表单。我目前有一个客户端表,它与 Lifepolicy 表有 hasMany 关系。在为人寿政策构建创建表单时,我不断收到未定义的变量。(使用 Laravel 5.8)这是我的代码:class Lifepolicy extends Model{ protected $guarded = [ 'id' ]; public function client() { return $this->belongsTo(Client::class); } public function addLifepolicy($lifepolicy) { $this->lifepolicies()->create($lifepolicy); }}class Client extends Model{ protected $guarded = [ 'id' ]; public function Lifepolicy() { return $this->hasMany(Lifepolicy::class); }} public function create(Request $request, Client $client) { return view('lifepolicies.create', $client); } Route::resource('/client/{client}/lifepolicy', 'ClientLifepolicyController');这是抛出错误的部分:<form role="form" method="POST" action="/client/{{ $client->id }}/lifepolicy">
1 回答
慕的地10843
TA贡献1785条经验 获得超8个赞
尝试这个 -
public function create(Request $request, Client $client)
{
return view('lifepolicies.create', compact('client'));
}
- 1 回答
- 0 关注
- 139 浏览
添加回答
举报
0/150
提交
取消