Closed ghost closed 8 years ago
Are you trying to search on coordinator's name? If that is the case then you can use eager loading or join queries for it work.
I tried eager loading,modified as per the tutorial on your site. However, now my issue is I am not storing the coordinators' full name, rather their first and last name separately. What I have currently: query
$centers = Center::query()->with('coordinator')->where('coordinator_id',Auth::user()->userable->id);
return $this->applyScopes($centers);
columns
'first_name' => [
'data' => 'coordinator.first_name',
'name' => 'coordinator.first_name',
'title' => 'Coordinator',
'searchable' => true,
],
edit method
->editColumn('first_name', function ($user) {
return Area_Coordinator::find($user->area_coordinator_id)->full_name;
})
I can search via the coordinators first name, however, since I want to search by that and the last name is there a way to concatenate both into one column? Or rather, apply my accessor method, or should I just include the last name column in the datatable?
Regards,
A trick you can do is add both columns on js but them so they can still be searchable:
'last_name' => [
'data' => 'coordinator.last_name',
'visible' => false,
'name' => 'coordinator.last_name',
],
'coordinator' => [
'data' => 'coordinator',
'name' => 'coordinator.first_name',
],
->addColumn('coordinator', function ($user) {
return Area_Coordinator::find($user->area_coordinator_id)->full_name;
})
Summary of problem or feature request
One-To-Many Relationship asserted via storing id of owning entity in table of many entity. E.g.: coordinator manages one or many centers. After setting the columns via the html builder, I edit the coodinator_id column and apply an accessor method to retrieve the coordinators full name:
My aim is to allow only the centers that belong to the authenticated coordinator to be displayed on the datatable unless the authenticated user is an admin as shown in my queries. However, if I enter the value of the Coordinator column that appears on the datatable it says no matching records found.
How do I achieve this?
Code snippet of problem
System details
Regards,