Hello,
I have a little issue with the filter option. I have sereval tables in my database which are linked by primary key.
It does something like this :
Site -> Parcel (has site_id) -> Tree (has parcel_id)
In my code, in TreeCrudCrontroller.php I do something like this :
$this->crud->addFilter([
'type' => 'text',
'name' => 'site',
'label' => 'Site'
],
false,
function ($value) {
$this->crud->addClause('join', 'parcels', 'parcel_id', 'parcels.id');
$this->crud->addClause('join', 'sites', 'parcels.site_id', 'sites.id');
$this->crud->addClause('where', 'sites.name', 'LIKE', "%$value%");
}
);`
$this->crud->addFilter([
'type' => 'text',
'name' => 'owner',
'label' => 'Propri茅taire'
],
false,
function ($value) {
$this->crud->addClause('join', 'parcels', 'parcel_id', 'parcels.id');
$this->crud->addClause('join', 'sites', 'parcels.site_id', 'sites.id');
$this->crud->addClause('join', 'owners', 'sites.owner_id', 'owners.id');
$this->crud->addClause('where', 'owners.first_name', 'LIKE', "%$value%");
}
);
In my Tree model, I have this code :
public function parcel()
{
return $this->belongsTo(Parcel::class);
}
public function displaySite()
{
$site = Tree::with('parcel.site')->find($this->id);
return $site->parcel->site->name;
}
public function displayOwner()
{
$owner = Tree::with('parcel.site.owner')->find($this->id);
return $owner->parcel->site->owner->full_name;
}
The problem is that when I show my table for the first time, without filters, both Site and Owner display the right text BUT when I filter on one of them, the ID of the current Tree is changing.
If I use to filter by Site, the Tree ID is changed by the Site ID
If I use to filter by Parcel, the Tree ID is changed by the Parcel ID
I don't know if I do something wrong or if it's a bug.
I'm on the lastest version of backpack/base and backpack/crud.
I hope that I'm as understandable as possible :)
Thanks for your help 馃憤
This is almost certainly data tables + laravel playing up; essentially with relations present, if select("the_base_table.*") wasn't the last thing called, the sorting would do what you're saying.
I cannot for the life of me find the URL where I found that.
Yeah, you're right.
After reading your message, I tried by myself in my PhpMyAdmin with a select * and a select my_table.*
The result without the my_table.* return this:

I didn't figured out before.
So Laravel just keep the last ID column. I just need to change the select.
But now I need to know how 8-)..
Found it in the Laravel doc
$this->crud->addClause('select', 'my_table.*');
Thanks for you help 馃憤
Most helpful comment
Found it in the Laravel doc
$this->crud->addClause('select', 'my_table.*');
Thanks for you help 馃憤