I want to merge restaurant name and location to be in one column, Im uisng laravel and I don't want to merge it using the editcolumn from the controller because this will not allow search to work and I will get in trouble as Im using eloquent as explain here https://github.com/yajra/laravel-datatables/issues/2293 so I have to return the same name as it comes from the elquent, but I need in the same time to combine tow columns in one
Please note, I cant use combination in controller and return it in one column
->editColumn('restaurant_name', function ($data) {
return $data->restaurant_name.' - '.$data->restaurant_city;
}) //this one cant be work because it will give me error message when do search
Javascript:
columns: [
{data: 'id', name: 'id', sClass: 'text-center'},
{data: 'user_name', name: 'users.name', sClass: 'text-center'},
{data: 'restaurant_name', name: 'restaurants.name', sClass: 'text-center'},
{data: 'restaurant_city', name: 'locations.city', sClass: 'text-center'},
{data: 'action', name: 'action', sClass: 'text-center',orderable: false, searchable: false},
],
Controller
return $this->select('orders.*', 'users.name')
->join("food_orders", "orders.id", "=", "food_orders.order_id")
->join("foods", "foods.id", "=", "food_orders.food_id")
->join("restaurant_locations", "restaurant_locations.id", "=", "orders.location_id")
->join("restaurants", "restaurants.id", "=", "foods.restaurant_id")
->join('users', 'orders.user_id', '=', 'users.id')
->select('orders.*',"users.name as user_name","restaurants.name as restaurant_name","restaurant_locations.city as restaurant_city")
->groupBy('orders.id');
return DataTables::of(Order::GetAllOrders())
->addIndexColumn()
->editColumn('created_at', function ($data) {
return date('d-m-Y', strtotime($data->updated_at));
})
->addColumn('action', function($row){
return view('admin.orders.all_orders.action-buttons',compact('row'))->render();
})
->rawColumns(['action'])
->make(true);