我有一个表格,可以从数据库中获取注册课程的各种学生的数据。现在在此表中,我想将"详细信息"按钮列绑定到特定学生,以便它从该特定学生的数据库中获取特定详细信息
定义Student
模型。然后定义您的Details
模型。一个学生有很多细节,因此在Student
模型中创建一个details
关系。
之后,您可以将$with
属性设置为预先加载关系。将$visible
属性设置为包含details
将使details
在Student
转换为数组时可见。
class Student extends Model
{
$with = ['details'];
$visible = ['id','name','details'];
function details ()
{
return $this->hasMany(Details::class);
}
}