Open mvpopuk opened 4 years ago
You can do this by adding an Accessor to the Model, then appending it so that it's available to use as any other column
For example, on the Model:
public function getFullNameAttribute() { return $this->first_name . ' ' . $this->last_name; }
protected $appends = [ 'full_name' ];
And then in the TableComponent you can use this like so:
Column::make('FullName')->searchable()->sortable(),
Now I have a problem with FullName
when searching:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customers.FullName' in 'where clause' (SQL: select count(*) as aggregate from `customers` where (`customers`.`id` like %bobo% or `customers`.`FullName` like %bobo% or `customers`.`phone` like %bobo% or `customers`.`mobile` like %bobo% or `customers`.`city` like %bobo% or `customers`.`postcode` like %bobo% or `customers`.`created_at` like %bobo%) and `customers`.`deleted_at` is null)
I think I have to extend or modify the query logic since I only want to search if the CONCAT
FirstName
and LastName
are equal with the input query
I will try to CONCAT $column . $column
see what happens :)
Hi Guys i have been having the same issue, have tried everything above but still getting an error if i try to search by full_name.
Sorting has this same issue
i tried something like this and it work
User::query()->selectRaw("*, concat('first_name','last_name') as full_name");
but sorting is buggy, it sort only once which i don't understand why
'
Column::make('Display Name','full_name')->sortable()->sortUsing(function ($models, $sort_attribute, $sort_direction) {
return $models->orderByRaw('full_name',[$sort_attribute, $sort_direction]);
}),
'
Thank you..
From: ranidentity notifications@github.com Reply to: kdion4891/laravel-livewire-tables reply@reply.github.com Date: Thursday, 28 January 2021 at 10:34 To: kdion4891/laravel-livewire-tables laravel-livewire-tables@noreply.github.com Cc: Sir-Nigel nigel@leadingdigital.africa, Comment comment@noreply.github.com Subject: Re: [kdion4891/laravel-livewire-tables] CONCAT two columns ? (#21)
i tried something like this and it work User::query()->selectRaw("*, concat('first_name','last_name') as full_name"); but sorting is buggy, it sort only once which i don't understand why 'Column::make('Display Name','full_name')->sortable()->sortUsing(function ($models, $sort_attribute, $sort_direction) { return $models->orderByRaw('full_name',[$sort_attribute, $sort_direction]); }),'
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
Hi, awesome package. I love it. If is possible I would like to sponsor it.
Anyways, is there a way to CONCAT two db columns like FirstName and LastName ?