I use laravel yajra/datatables
in my order model there is a one to many relations between driver and order in some cases the driver_id
becomes NULL
in cases so what i want to do is to print a default value in case if there is no driver
for this order here is my OrderDataTable
file
query method
public function query()
{
return Order::select('id', 'client_name', 'phone', 'price', 'shipping_price', 'city_id', 'status_id', 'driver_id')
->with('city:id,name')
->with('status:id,name')
->with('driver:id,name')
->orderBy('id', 'desc');
}
getColumns method
protected function getColumns()
{
return [
Column::make('client_name'),
Column::make('phone'),
Column::make('Price')->data('price'),
Column::make('Shipping')->data('shipping_price')->name('shipping_price'),
Column::make('City')->data('city.name')->name('city.name'),
Column::make('Status')->data('status.name')->name('status.name'),
Column::make('Driver')->data('driver.name')->name('driver.name'), // this is the column that i want to add default value for
Column::computed('action')
->exportable(false)
->printable(false)
->addClass('text-center'),
];
}