addSelect is not working on $table->query()
I'm trying to select a custom column in my query, but ->addSelect on the query broke the table. Is there other option to select a custom column?
22 Replies
No errors?
I think the problem is thet when I add addSelect to the query, it overwrites the default selects
This is my query
If I remember correctly it makes a second query and doesn't overwrite other selects
If I add all the fields that I'm using it is working
but this would be the meaning of addSelect to not overwrite current selects just add a new one
this is for the view record?
This is a table
try
return parent::getEloquentQuery()->addSelect([DB::raw('total * price as total_price')])
This has no parent::getEloquentQuery
where do you put your code? which file? which method?
This is a simple livewire component
I added HasTable and InteractsWithTable
you are on v2?
v3
i don't get it then where you add query
but you show query with return
the query method first parameter can be a clouser that returns a query
This is my whole query, I just simplied it down to be more understandable
Right now it works with the select but then I loses features such as groups on table
your query is just a mess
why do you need those joins? filament should eager load everything
@krekas this is some aggregated data, I have event with days with meals with recipes with ingredients, and I need a list where all the ingredients are listed that are required for an event, and also the amount of the ingredient summed up. Yes, we could do a solution to eagerload and then calculate in PHP these sums, but that way you cannot order by the sums, so the sum needs to be in the query. Anyways if I remove the $join and only create an addSelect it is still not working, so that is why I simplied it down to be more understandable