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
->groupByRaw('vehicle_id, date(start_at)')
->groupByRaw('vehicle_id, date(start_at)')
?
Dan Harrin
Dan Harrin2y ago
you cant group in eloquent queries it fucks up the model hydration because of that, you cant properly group in filament tables
RichtheKid
RichtheKidOP2y ago
So there is no way to achieve grouping?
Dan Harrin
Dan Harrin2y 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
RichtheKidOP2y 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 Harrin2y ago
is it a custom page?
RichtheKid
RichtheKidOP2y 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 Harrin2y 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
RichtheKidOP2y 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 Harrin2y ago
if you just define public $record in the widget, it will be filled by livewire from that array
RichtheKid
RichtheKidOP2y ago
alright and to set the value what do i use? Since a custom page doesnt have a record by default
Dan Harrin
Dan Harrin2y 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
RichtheKidOP2y 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 Harrin2y ago
show me the code in the 3 files
RichtheKid
RichtheKidOP2y ago
Widget blade file
Dan Harrin
Dan Harrin2y ago
try extending the ViewRecord class instead of Page, then remove the $record property on that class
RichtheKid
RichtheKidOP2y ago
This is the concept i am going for but ill try the viewrecord class
RichtheKid
RichtheKidOP2y 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 Harrin2y ago
so where are you setting the record on the page viewrecord assumes that the record is in the url
RichtheKid
RichtheKidOP2y ago
RichtheKid
RichtheKidOP2y ago
just like setting a property does the widget aswell?
Dan Harrin
Dan Harrin2y ago
where is this the widget recieves data from the widget-data which is passed from the page
RichtheKid
RichtheKidOP2y ago
CustomPage.php file
Dan Harrin
Dan Harrin2y 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
RichtheKidOP2y ago
Hmm I see!
Want results from more Discord servers?
Add your server