Eloquent 也会假定每个数据表都有一个名为 id
的主键字段。你可以定义一个访问权限为 protected
的 $primaryKey
属性来覆盖这个约定。
另外,Eloquent 假定主键是一个递增的整数值,这意味着在默认情况下主键会自动转换为 int
。如果希望使用非递增或者非数字的主键,则必须在模型上设置 public $incrementing = false
。如果主键不是一个整数,你应该在模型上设置 protected $keyType = string
。
如果不设置 public $incrementing = false hasOne() 里不能使用主键
报错 : Call to a member function addEagerConstraints() on null 是因为 model 关系没有 return
中间表关系
return $this->hasManyThrough(
Labels::class,
CourseLabels::class,
'course_id',
'label_id',
'course_id',
'label_id'
);
一个页面加载多个分页 :
paginate : 的参数
$perPage = null,
$columns = ['*'],
$pageName = 'page',
$page = null
在设置分页方法的时候传入自定分页变量名,格式为 paginate(3, ['*'], 'spage');这样问题就解决了,可以在同一个页面上实现多个分页。
但是,你以为ok了么?