我正在尝试对我的laravel 5.4 (https://github.com/Kyslik/column-sortable)使用列排序,
我的模型:
class InfoBird extends Model
{
public $timestamps = false;
protected $primaryKey = "id_oiseau";
protected $table = "oiseau";
use Sortable;
public $sortable = [
'nom_codifie',
'nom_commun',
'etat_actuel',
'pays',
'date_reception',
'date_renvoi',
'immatriculation',
'nom_local'
];
public function getBirds() {
$birds = DB::table('oiseau as oi')
->leftJoin('local_lpo', 'oi.id_local_lpo', 'local_lpo.id_local_lpo');
return $birds;
}
}我的控制器:
public function birds() {
$infoBirds = new InfoBird;
$birds = $infoBirds->getBirds();
$birds = $birds->sortable()->paginate(15);
//$birds = InfoBird::sortable()->paginate(15);
return view('pages.birds', compact('birds'));
}在我添加模型之前,它是有效的(只有注释中的句子)。但现在我有了这个错误:
Call to undefined method Illuminate\Database\Query\Builder::sortable()
我已经没有办法解决这个问题了,非常感谢你的帮助!
发布于 2017-07-21 18:20:41
getbirds()返回一个QueryBuilder,因此您尝试访问的是QueryBuilder的sortable方法(不存在),而不是模型Infobird的sortable方法(确实存在)。
试试这个:
$info = Infobird::sortable()->leftjoin('local_lpo', 'oi.id_local_lpo', 'local_lpo.id_local_lpo')->paginate(15);
return view('pages.birds', compact('birds'));https://stackoverflow.com/questions/45234486
复制相似问题