【发布时间】:2021-07-23 19:30:24
【问题描述】:
我想将当前选定的用户 ID 传递给 livewire 中的 showmodal,并且每次尝试单击显示模式按钮时都会收到此错误: enter image description here 如果我删除 {{$user->id}} 会出现显示模式,但是当我提交输入的数据时,我得到了同样的错误,例如: enter image description here 这是我的模型数据方法: /** * 此组件中映射的模型的数据 *。
* * @return void */
public function modelData()
{
return [
'user_id' => auth()->user()->id,
'related_id' => $this->user->id,
'treatment' => $this->treatment,
'sub_treatment' => $this->sub_treatment,
'status' => $this->status,
];
}
创建方法:
/** * The create function.
* * @return void */
public function create()
{
$this->validate();
Appointment::create($this->modelData());
$this->modalFormVisible = false; $this->reset();
}
创建显示模式是:
/** * Shows the create modal
* * @return void */
public function createShowModal()
{
$this->resetValidation();
$this->reset();
$this->modalFormVisible = true;
}
和渲染方法如:
public function render()
{
return view('livewire.user-appointments', [ 'data' => $this->read(), ]);
}
和模态关系是: 应用\用户
public function appointments()
{
return $this->hasMany('App\Models\Appointment');
}
应用\约会
public function user()
{
return $this->belongsTo('App\Models\User');
}
请帮忙!
【问题讨论】:
-
你能分享完整的组件代码和刀片代码吗???您如何检索 $user 并绑定到刀片?
-
我分享了我的组件
标签: php components laravel-8 laravel-livewire