gpt4 book ai didi

laravel - 带有连接的 yajra DataTable 在 laravel 5 中不起作用?

转载 作者:行者123 更新时间:2023-12-04 21:10:33 25 4
gpt4 key购买 nike

客户与工作的关系

 public function customer() {
return $this->belongsTo('App\Customer','customerid');
}

public function jobs(){
return $this->hasMany('App\Job','customerid');
}


在 Controller 中

protected  function getJobs(){
$jobs = Job::Join('customer','jobs.customerid','=','customer.id')
->select(array('jobs.id','customer.firstname','customer.lastname','jobs.jobstatus','jobs.trialdate','jobs.deliverydate'));
return Datatables::of($jobs)
->addColumn('action', '<a class="btn btn-default btn-xs" data-toggle="tooltip" data-placement="top" title="Edit" href="{{ URL::to(\'updatejob/\'.$id) }}"><i class="fa fa-pencil"></i></a>')
->make();

}

它抛出以下错误

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'order clause' (SQL: select `jobs`.`id`, `customer`.`firstname`, `customer`.`lastname`, `jobs`.`jobstatus`, `jobs`.`trialdate`, `jobs`.`deliverydate` from `jobs` inner join `customer` on `jobs`.`customerid` = `customer`.`id` order by `0` asc limit 10 offset 0)


我从 2 天起就被困在这个问题上,请帮助我摆脱这个问题

最佳答案

我认为您在查询中错过了“order by”,试试这个:

protected  function getJobs(){
$jobs = Job::Join('customer','jobs.customerid','=','customer.id')
->select(array('jobs.id','customer.firstname','customer.lastname','jobs.jobstatus','jobs.trialdate','jobs.deliverydate'))
->orderBy('customer.lastname')->get();
return Datatables::of($jobs)
->addColumn('action', '<a class="btn btn-default btn-xs" data-toggle="tooltip" data-placement="top" title="Edit" href="{{ URL::to(\'updatejob/\'.$id) }}"><i class="fa fa-pencil"></i></a>')
->make();

}

关于laravel - 带有连接的 yajra DataTable 在 laravel 5 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35520805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com