Error table query for table widget

I have this query that i use to group data per day. To calculate the total of a vehicle per day. I initially tried creating a table widget with this query and I got an error (image 2). But when I tried it on a custom page that implements hasTable with InteractsWithTable the same query worked. Could anyone help?
26 Replies
LeandroFerreira
LeandroFerreira15mo ago
->groupByRaw('vehicle_id, date(start_at)')
->groupByRaw('vehicle_id, date(start_at)')
?
Dan Harrin
Dan Harrin15mo ago
you cant group in eloquent queries it fucks up the model hydration because of that, you cant properly group in filament tables
RichtheKid
RichtheKid15mo ago
So there is no way to achieve grouping?
Dan Harrin
Dan Harrin15mo ago
in v3 there is row grouping feature with column totals but not in v2. it would need to be a custom livewire component / view instead of the table builder
RichtheKid
RichtheKid15mo ago
Alright, I'll make a custom component. Another question, is it possible to pass data from a selected record to a widget on the same page? If yes, how?
Dan Harrin
Dan Harrin15mo ago
is it a custom page?
RichtheKid
RichtheKid15mo ago
yes Basically I have a table where you can select a vehicle and then the widget shows additional information for that specific record id.
Dan Harrin
Dan Harrin15mo ago
GitHub
How to pass variable to Stats overview and chart widgets · filament...
I want to display stats overview or chart inside detail (custom) page, but I need to check data base on that particular $id Any suggestion to pass ID to the widgets and access that ID in another cl...
RichtheKid
RichtheKid15mo ago
Is there like a line of code to set the record. Something like $this->record = something? Or am I getting the wrong idea?
Dan Harrin
Dan Harrin15mo ago
if you just define public $record in the widget, it will be filled by livewire from that array
RichtheKid
RichtheKid15mo ago
alright and to set the value what do i use? Since a custom page doesnt have a record by default
Dan Harrin
Dan Harrin15mo ago
the contents of the widget-data array will be matched up to properties of the same name on the widget inside the page view, you can access the current livewire component with $this or all public properties as variables you could extend the ViewRecord page class if you want which will add a $record property that gets autofilled for you from the url
RichtheKid
RichtheKid15mo ago
I added the widget data line in the blade file of my custom page. But my custom widget still has $record returning null.
Dan Harrin
Dan Harrin15mo ago
show me the code in the 3 files
RichtheKid
RichtheKid15mo ago
Widget blade file
Dan Harrin
Dan Harrin15mo ago
try extending the ViewRecord class instead of Page, then remove the $record property on that class
RichtheKid
RichtheKid15mo ago
This is the concept i am going for but ill try the viewrecord class
RichtheKid
RichtheKid15mo ago
since the custom page doesn't have a record selected yet. I believe viewrecord wouldn't work. The widget below serve to show additonal information based on the selected vehicle next to the information displayed in the first table
Dan Harrin
Dan Harrin15mo ago
so where are you setting the record on the page viewrecord assumes that the record is in the url
RichtheKid
RichtheKid15mo ago
RichtheKid
RichtheKid15mo ago
just like setting a property does the widget aswell?
Dan Harrin
Dan Harrin15mo ago
where is this the widget recieves data from the widget-data which is passed from the page
RichtheKid
RichtheKid15mo ago
CustomPage.php file
Dan Harrin
Dan Harrin15mo ago
which method because it needs to be in mount() because after the page loads the widget wont recieve new data if the widget needs to recieve data after the page loads, you need to use a Livewire event instead
RichtheKid
RichtheKid15mo ago
Hmm I see!