Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yajra DataTable with join not working in laravel 5?

relation of customer with job

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

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

in 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();
			
    }
it throw following error

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)

i'm stuck in this issue from 2 day please help me to get out from this

like image 386
Swapnil Tembhurnikar Avatar asked Oct 30 '22 09:10

Swapnil Tembhurnikar


2 Answers

I think you missed "order by" in your query, try this :

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();

}
like image 128
BKF Avatar answered Nov 10 '22 20:11

BKF


I simply update the composer ->php composer.phar update Its working fine now Thanks

like image 31
Swapnil Tembhurnikar Avatar answered Nov 10 '22 21:11

Swapnil Tembhurnikar