1.路由不支持 -
// 报错
Route::get('/user/{role-id}', 'UserController@index');
// 正确
Route::get('/user/{id}', 'UserController@index');
- object 没有 isEmpty()
// 错误
$object->isEmpty()
- 方法 - 返回值
// collection object/null
->get();
- 关联查询
// where/wherehas 条件查询,对筛选有约束, 不显示数据
// with 对筛选可以约束,显示数据
Illuminate\Database\Query\Builde
Illuminate\Database\Eloquent\Builder
$sheets = Sheet::whereHas('CourseSheets', function ($query) use ($courseId){
$query->where('course_id', $courseId);
})->scopes(['OrderTest', 'OrderSeq'])->get();
“message”: "Type error: Argument 1 passed to App\Models\Sheet::scopeOrderTest() must be an instance of Illuminate\Database\Query\Builder, instance of Illuminate\Database\Eloquent\Builder given
应该写成
$sheets = Sheet::scopes(['OrderTest', 'OrderSeq'])->whereHas('CourseSheets', function ($query) use ($courseId){
$query->where('course_id', $courseId);
})->get();
// 错误
public function scopeOrderSeq(Builder $query)
{
return $query->orderBy('seq', 'asc');
}
// 正确
public function scopeOrderSeq($query)
{
return $query->orderBy('seq', 'asc');
}