Aditya Khadka | Nepal
Disable Previous Dates in End Date Picker - User Should Not Select Before Release Date
I'm trying to disable dates in the end_date picker so that users cannot select any date before the release_date using Filament's DatePicker. Here's what I have so far:
Forms\Components\DatePicker::make('release_date')
->required()
->reactive()
->afterStateUpdated(function (Set $set, Get $get, $state, string $operation) {
$releaseDate = Carbon::parse($state);
// Update the minimum date for the end_date based on the selected release_date
$set('release_date_min', $releaseDate);
}),
Forms\Components\DatePicker::make('end_date')
->required(),
What I'm trying to achieve:
Users should only be able to select an end_date that is equal to or after the release_date.
P
How can I properly disable dates in the end_date picker that are earlier than the release_date?
Thanks for any help or insights!
16 replies
Run function while creating record not on editing.
Hi everyone, I'm working on a Filament project, specifically in the MovieManagementResource, and I want to run the generateDateSchedules method only when creating a new movie. I am trying to use request()->routeIs('filament.admin.resources.movie-managements.create') in the afterStateUpdated callback of the DatePicker, but it doesn't seem to be working. Here’s part of my code:
Forms\Components\DatePicker::make('release_date')
->required()
->reactive()
->afterStateUpdated(function (Set $set, Get $get, $state) {
if (request()->routeIs('filament.admin.resources.movie-managements.create')) {
$releaseDate = Carbon::parse($state);
$endDate = Carbon::parse($get('end_date'));
if ($endDate) {
self::generateDateSchedules($set, $releaseDate, $endDate);
}
}
});
6 replies
Update sum on filter
Hello, community. I have a table showing how many times users have ordered with the amount. When I do the date filter, I need to fetch a user with an order between that date which is already done and update the table result accordingly which is total order within that date and amount.
my table code is
Tables\Columns\TextColumn::make('total_order')
->color('primary')
->default(fn (Customer $record) => $record->orders->count())
->description(fn (Customer $record): string => "€{$record->orders ->sum('total')}")
->label('Total Order'),
and my filter code is
//this week
Filter::make('This Week')
->query(fn (Builder $query): Builder => $query->whereHas('orders', function (Builder $query) {
$query->whereBetween('created_at', [now()->startOfWeek(), now()->endOfWeek()]);
})),
2 replies
Apply date filter Globally to aggregate result in table
Hello, everyone! I'm working with Laravel Filament and facing a challenge in dynamically filtering and aggregating data within a table column definition based on URL parameters. Specifically, I want to apply a date range filter from URL parameters to count and sum each customer's total orders and prices within that range. The filter is used globally, and now I need to reflect this filtered context within individual table columns for aggregate values.
note my date filter code is
Filter::make('scheduled_date_time')
->form([
Forms\Components\DatePicker::make('created_from'),
Forms\Components\DatePicker::make('created_until'),
])
->query(function (Builder $query, array $data): Builder {
return $query->whereHas('orders', function (Builder $query) use ($data) {
$query->when(
$data['created_from'],
fn (Builder $query, $date): Builder => $query->whereDate('scheduled_date_time', '>=', $date)
)->when(
$data['created_until'],
fn (Builder $query, $date): Builder => $query->whereDate('scheduled_date_time', '<=', $date)
);
});
});
Based on that, I want the total order and total count of users in that date range.
Tables\Columns\TextColumn::make('total_order')
->default(function (Customer $record) {
// Need to apply filtered date range here for counting and summing
return $record->orders->count(); // How to include filtering?
})
->label('Total Order');
2 replies
Show orderitems associated with orders
I'm currently working on a project where I have two main models: Order and OrderItem, with Order containing many OrderItems. In the Filament admin panel, I'm trying to implement a feature within the Order resource where I can click an action button for an order to view all its associated order items in a table.
I attempted to create a custom action in the Order resource to achieve this, hoping to navigate to a view or page where I see a table listing all the OrderItems associated with that specific Order. Here's the code snippet I've used:
use Filament\Pages\Actions\Action;
Action::make('view Order Id')
->url(fn (): string => OrderItemResource::getUrl('view', ['record' => $this->order->id]));
2 replies
Displaying 'New' and 'Old' Changes from Spatie Activity Log in an InfoList
Hello everyone! 👋
I'm using the Spatie Activity Log package in my Laravel project to track model changes. The package logs the 'new' and 'old' values of the changed attributes in the
properties
field, and this data is stored as a collection.
I'm facing an issue with displaying these values in a user-friendly way in my InfoList component. I want to compare the 'old' and 'new' values side by side.
Here's what I have so far:
- I've set up the Activity Log, and it's working fine; changes are being logged correctly.
- I can access the properties
field in my activity log model, which gives me a collection containing 'new' and 'old' values.
properties= ({"attributes":{"title":"Pizza cheese sticks","price":4.5,"dine_in_price":0},"old":{"title":"Pizza cheese stick","price":4.5,"dine_in_price":0}})
My question is: How can I efficiently parse and display this data in an InfoList? I'm looking for a way to iterate over the 'attributes' and 'old' arrays within the properties
collection and present them in a tabular or side-by-side format for easy comparison.
Any suggestions or examples of how you've tackled a similar situation would be greatly appreciated!
Thank you in advance!5 replies
Seeking Guidance on Setting Default Rows for KeyValue Component in FilamentPHP
I'm working on a Laravel project using FilamentPHP and I've encountered an issue with the KeyValue component. I'm trying to set default rows for this component but haven't been successful. Here's what I've tried so far:
KeyValue::make('test_key_value')
->default([
['key' => 'Test', 'value' => 'row1_value'],
['key' => 'row2_key', 'value' => 'row2_value'],
// Additional rows
]),
This code doesn't seem to work as I expected. The default rows are not being initialized as intended. I'm particularly interested in setting these default rows for editing existing records, not just for creating new records.
Could someone please provide insights or guidance on how to properly set default rows for the KeyValue component in this context? If there's a specific approach or a code snippet that works well for this scenario, I would greatly appreciate it.
Thank you in advance for your help!
2 replies