nowak
nowak
FFilament
Created by nowak on 10/28/2024 in #❓┊help
How to use CreateAction for a resource in an unrelated resources table headerActions?
I have recently experimented with adding a CreateAction to a resource tables headerActions, but this fails as I get the error:
Method Filament\Actions\CreateAction::table does not exist.
Method Filament\Actions\CreateAction::table does not exist.
But I was able to add my CreateAction to the ListResource pages getHeaderActions() method, like so:
protected function getHeaderActions(): array
{
return [
CreateAction::make('userOrder')
->label('Create User Order')
->model(UserOrder::class)
->form(UserOrderResource::getFormSchema()),
];
}
protected function getHeaderActions(): array
{
return [
CreateAction::make('userOrder')
->label('Create User Order')
->model(UserOrder::class)
->form(UserOrderResource::getFormSchema()),
];
}
Would it be possible to add the functionality of this action to the tables headerActions instead of List page header actions? The main reason for me wanting to move the the table header, is for the placement in the UI, to avoid having the action buttons spread out too much.
2 replies
FFilament
Created by nowak on 10/24/2024 in #❓┊help
How to add a CreateAction in the headerActions of resource A, to create a record in resource B?
I want to allow users to easily create a record in resource B, on the List page of resource A in its tables headerActions. I would also prefer to use the existing form from resource B as well as it's create lifecycle hooks, if possible. Basically, I want to open the existing create page of resource B in a modal by clicking an action button, which does the exact same as the existing create page does. Is this possible? I tried to use Filament\Actions\CreateAction on a tables headerActions just to test if this would open a create modal when clicked like this:
->headerActions([
\Filament\Actions\CreateAction::make()
->model(UserOrder::class)
->form([
TextInput::make('status_id')
->required()
->maxLength(255),
// ...
]),
]);
->headerActions([
\Filament\Actions\CreateAction::make()
->model(UserOrder::class)
->form([
TextInput::make('status_id')
->required()
->maxLength(255),
// ...
]),
]);
But this gives this error:
Method Filament\Actions\CreateAction::table does not exist.
Method Filament\Actions\CreateAction::table does not exist.
23 replies
FFilament
Created by nowak on 10/24/2024 in #❓┊help
How to remove createAnother button from createOptionAction modal?
In a Form Select field, when I want to add the abilitiy to create another option on the relationship, it only makes sense in some cases to add one extra option that needs to be selected by the select field. Here I do not want to see the "Create & create another" action in my modal, as this only confuses the end user. This does not work:
->createOptionAction(function (Action $action) {
return $action
->createAnother(false)
}),
->createOptionAction(function (Action $action) {
return $action
->createAnother(false)
}),
As:
Method Filament\Forms\Components\Actions\Action::createAnother does not exist.
Method Filament\Forms\Components\Actions\Action::createAnother does not exist.
How can we remove this action from the createOptionAction modal?
10 replies
FFilament
Created by nowak on 10/23/2024 in #❓┊help
Database notifications panel stays open after clicking ->url() notification action in spa mode
I recently enabled spa mode on my filament admin panel, where I have noticed that the database notifications panel stays open after navigating to a resource page from a notification url action. Also it seems like the css sometimes (at random it) does some weird stuff causing some elements in the navigation sidebar to flash when clicking the notification action buttons. I have attached a screen recording of the issue. And here is the code for how one of these notifications are created:
$superAdmins = User::role('super_admin')->get();

foreach ($superAdmins as $superAdmin) {
Notification::make()
->title(Lang::get('complaint.admin.title.new_complaint', [
'user' => $complaint->userOrder->user->full_name,
'group' => $complaint->userOrder->group->name
]))
->body(Lang::get('complaint.admin.content.new_complaint', [
'user' => $complaint->userOrder->user->full_name,
'group' => $complaint->userOrder->group->name
]))
->actions([
Action::make('view')
->label(Lang::get('complaint.admin.label.view_complaint'))
->button()
->url(ComplaintResource::getUrl('view', ['record' => $complaint]))
->markAsRead()
])
->broadcast($superAdmin)
->sendToDatabase($superAdmin);
event(new DatabaseNotificationsSent($superAdmin));
}
$superAdmins = User::role('super_admin')->get();

foreach ($superAdmins as $superAdmin) {
Notification::make()
->title(Lang::get('complaint.admin.title.new_complaint', [
'user' => $complaint->userOrder->user->full_name,
'group' => $complaint->userOrder->group->name
]))
->body(Lang::get('complaint.admin.content.new_complaint', [
'user' => $complaint->userOrder->user->full_name,
'group' => $complaint->userOrder->group->name
]))
->actions([
Action::make('view')
->label(Lang::get('complaint.admin.label.view_complaint'))
->button()
->url(ComplaintResource::getUrl('view', ['record' => $complaint]))
->markAsRead()
])
->broadcast($superAdmin)
->sendToDatabase($superAdmin);
event(new DatabaseNotificationsSent($superAdmin));
}
Is this how it is supposed to be, or is this a bug?
6 replies
FFilament
Created by nowak on 10/17/2024 in #❓┊help
Logo missing from mobile top bar + navigation(false)
No description
2 replies
FFilament
Created by nowak on 10/17/2024 in #❓┊help
Show navigation and topbar conditionally
In my panel provider I am disabling the navigation and topbar like this:
->navigation(false)
->topbar(false)
->navigation(false)
->topbar(false)
Since I actually only want to do this for specific roles, I wonder if there is a way to set this conditionally? This does not seem to be working:
->navigation(fn() => auth()->user()->hasRole('super_admin'))
->navigation(fn() => auth()->user()->hasRole('super_admin'))
10 replies
FFilament
Created by nowak on 10/14/2024 in #❓┊help
I get Class "App\Filament\Pages\Dashboard" not found after removing Dashboard on Production
I wanted to create a custom dashboard instead of the default panel dashboard. I named my custom dashboard class something other than Dashboard, which I had no issues with when developing locally. Then when pushing my changes to Production (Staging environment), I get the Class "App\Filament\Pages\Dashboard" not found error. Has anyone else experienced something similar? It is very strange that I get the error on production but not locally.
25 replies
FFilament
Created by nowak on 10/11/2024 in #❓┊help
In a iconButton action, is it possible to make the iconSize larger than Large without using css?
I have this view action:
Tables\Actions\ViewAction::make()
->iconButton()
->size('xl'),
Tables\Actions\ViewAction::make()
->iconButton()
->size('xl'),
When setting ->size('xl'), this is macthed in the icon-button.blade.php to the icon size Large, which is h6 w6. This is a bit too small for comfortable touch usage, where the minimum size of h10 w10 is recommended. So is there a way to either add an extra attribute to the svg icon element, or set the size of the icon to 40px somehow? Or are we limited to the Filament\Support\Enums\IconSize enums?
4 replies
FFilament
Created by nowak on 10/9/2024 in #❓┊help
How to set ->recordAction(null) and ->recordUrl(null) conditionally in custom column?
I am working on a custom column class and view, which should function as a confirmation slider. The issue is that when I drag the slider handle and release outside the slider component, the record row is receiving a click, which triggers the table rows recordAction. I could set ->recordAction(null) and ->recordUrl(null) on my table, but I might not always want to disable row clicks on all tables that use this custom column. So I was wondering if I could somehow conditionally set the recordAction table prop to null when my slider is in the dragging state, to avoid the record click being triggered while interacting with the confirmation slider?
5 replies
FFilament
Created by nowak on 10/8/2024 in #❓┊help
Browser refresh not working in new panel
I have created a new panel in my filament app on top of my admin panel. I have added a resource to my new panel, and it seems to work well. But I noticed that when I update my new panel resource code, the admin panel browser tabs are refreshing, but not my new panel browser tabs. So it seems I need to make an extra step to get browser refresh to work with my new panel when vite hot reloads. I could not find anything about this in the Filament documentation, any help is much appreciated.
35 replies
FFilament
Created by nowak on 10/7/2024 in #❓┊help
How to avoid showing all widgets on all dashboard pages?
Hi, I want to create multiple dashboards, each with their own specific widgets. I have this kitchen dashboard for example:
?php

namespace App\Filament\Pages;

use App\Models\MealType;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Pages\Dashboard as BaseDashboard;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;

class KitchenDashboard extends BaseDashboard
{

use BaseDashboard\Concerns\HasFiltersForm;

protected static ?string $title = 'Kitchen Dashboard';
protected static ?string $navigationIcon = 'icon-chef-hat';
protected static string $routePath = 'kitchen';

public function filtersForm(Form $form): Form
{
return $form
->schema([
Section::make()
->schema([
DatePicker::make('deliveryDate')
->formatStateUsing(fn ($state) => $state ?? now()->format('Y-m-d')),
Select::make('mealType')
->options(fn() => MealType::all()
->sortBy('id')
->where('is_visible','true')
->pluck('name', 'id')
->map(function ($name) {
return ucfirst($name);
})
)
->default(2)
->selectablePlaceholder(false)
->native(false)
])
->columns(2),
]);
}
}
?php

namespace App\Filament\Pages;

use App\Models\MealType;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Pages\Dashboard as BaseDashboard;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;

class KitchenDashboard extends BaseDashboard
{

use BaseDashboard\Concerns\HasFiltersForm;

protected static ?string $title = 'Kitchen Dashboard';
protected static ?string $navigationIcon = 'icon-chef-hat';
protected static string $routePath = 'kitchen';

public function filtersForm(Form $form): Form
{
return $form
->schema([
Section::make()
->schema([
DatePicker::make('deliveryDate')
->formatStateUsing(fn ($state) => $state ?? now()->format('Y-m-d')),
Select::make('mealType')
->options(fn() => MealType::all()
->sortBy('id')
->where('is_visible','true')
->pluck('name', 'id')
->map(function ($name) {
return ucfirst($name);
})
)
->default(2)
->selectablePlaceholder(false)
->native(false)
])
->columns(2),
]);
}
}
This dashboard shows all my widgets in app/Filament/Widgets/, as if BaseDashboard automatically fetches and returns all existing widgets. How can I avoid this, and select which widgets should be shown on which dashboards?
38 replies
FFilament
Created by nowak on 9/30/2024 in #❓┊help
Duplicate notifications from table action on page load
I have a UserOrderResource, where I have added a table action that navigates to the GroupOrderResource record for each UserOrder record:
Tables\Actions\Action::make('group_order')
->url(function (UserOrder $record): ?string {
// Use the already eager-loaded groupOrder if it's available
$groupOrder = $record->groupOrder()->withTrashed()->first();

// Check if the groupOrder exists and is not trashed
if (!$groupOrder || $groupOrder->trashed()) {

// Show a notification to the user
Notification::make()
->warning()
->title('Group Order Not Available')
->body("The group order for the user order by {$record->detail->full_name} with deadline: {$record->deadline} and id: {$record->id} is no longer available.")
->persistent()
->send();

return null; // Halt the action by not returning a URL
}
return GroupOrderResource::getUrl('edit', ['record' => $groupOrder]);
}),
Tables\Actions\Action::make('group_order')
->url(function (UserOrder $record): ?string {
// Use the already eager-loaded groupOrder if it's available
$groupOrder = $record->groupOrder()->withTrashed()->first();

// Check if the groupOrder exists and is not trashed
if (!$groupOrder || $groupOrder->trashed()) {

// Show a notification to the user
Notification::make()
->warning()
->title('Group Order Not Available')
->body("The group order for the user order by {$record->detail->full_name} with deadline: {$record->deadline} and id: {$record->id} is no longer available.")
->persistent()
->send();

return null; // Halt the action by not returning a URL
}
return GroupOrderResource::getUrl('edit', ['record' => $groupOrder]);
}),
I tried to add the conditional logic and notification to ->before(), but it was ignored entirely and when clicking the action, so I added this logic directly to the ->url() method. But I experience some strange behaviour, as these notifications are sent when the table is loaded, which makes sense as the url is generated before the action is clicked. But each notification is sent twice, which is odd to me. Is this due to my action code, or is filament triggering the action code twice on page load?
2 replies
FFilament
Created by nowak on 9/10/2024 in #❓┊help
Is it possible to add validation to a `Action::make()` before opening the confirmation modal?
I have added a header action to my table, where I have tried to add validation in the ->before() lifecycle hook:
Action::make('acceptAll')
->before(function ($action, $livewire) {
Log::debug('Before hook');
$groupOrders = $livewire->getTableRecords();
foreach ($groupOrders as $groupOrder) {
if (!$groupOrder->courier) {
Notification::make()
->warning()
->title('Missing Courier')
->body('Group order with route ID ' . $groupOrder->route->id . ' does not have a courier assigned. Please assign a courier and try again.')
->persistent()
->send();
$action->cancel();
return;
}
}
})
->requiresConfirmation()
->action(function ($action, $livewire) use ($orderStatusIds){
// Action logic
}),
Action::make('acceptAll')
->before(function ($action, $livewire) {
Log::debug('Before hook');
$groupOrders = $livewire->getTableRecords();
foreach ($groupOrders as $groupOrder) {
if (!$groupOrder->courier) {
Notification::make()
->warning()
->title('Missing Courier')
->body('Group order with route ID ' . $groupOrder->route->id . ' does not have a courier assigned. Please assign a courier and try again.')
->persistent()
->send();
$action->cancel();
return;
}
}
})
->requiresConfirmation()
->action(function ($action, $livewire) use ($orderStatusIds){
// Action logic
}),
But the before hook does not trigger before the confirmation modal is opened. Am I doing something wrong? Or is there simply no lifecycle hook that triggers before the action modal is opened?
7 replies
FFilament
Created by nowak on 9/9/2024 in #❓┊help
How to add `created_at` column with `sortable()` to `BelongsToMany` RelationManager correctly
I have a RelationManager with a BelongsToMany relationship, and both the pivot table and the relationship table has a created_at column. I try to add the column to the table like this:
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('first_name')
->columns([
Tables\Columns\TextColumn::make('full_name'),
Tables\Columns\TextColumn::make('role'),
Tables\Columns\TextColumn::make('created_at')->dateTime()
->dateTime('M j Y, H:i')
->sortable()
])
//.......
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('first_name')
->columns([
Tables\Columns\TextColumn::make('full_name'),
Tables\Columns\TextColumn::make('role'),
Tables\Columns\TextColumn::make('created_at')->dateTime()
->dateTime('M j Y, H:i')
->sortable()
])
//.......
This shows a date column in my table as expected, but when I try to sort the table by the created_at column, I get this Ambiguous column error:
local.ERROR: SQLSTATE[42702]: Ambiguous column: 7 ERROR: ORDER BY "created_at" is ambiguous
LINE 1: ...r_id" where "group_user"."group_id" = $1 order by "created_a...
^ (Connection: pgsql, SQL: select "group_user"."group_id" as "pivot_group_id", "group_user"."user_id" as "pivot_user_id", "group_user"."role" as "pivot_role", "group_user"."is_creator" as "pivot_is_creator", "group_user"."current_meal_type_id" as "pivot_current_meal_type_id", "group_user"."created_at" as "pivot_created_at", "group_user"."updated_at" as "pivot_updated_at", "group_user".*, "users".* from "users" inner join "group_user" on "users"."id" = "group_user"."user_id" where "group_user"."group_id" = 4 order by "created_at" asc limit 10 offset 0) {"view":{"view":"/Users/kaspernowak/development/meinrad/meinrad_laravel/filament/packages/tables/resources/views/index.blade.php","data":[]},"userId":6,"exception":"[object] (Spatie\\LaravelIgnition\\Exceptions\\ViewException(code: 0): SQLSTATE[42702]: Ambiguous column: 7 ERROR: ORDER BY \"created_at\" is ambiguous
LINE 1: ...r_id\" where \"group_user\".\"group_id\" = $1 order by \"created_a...
local.ERROR: SQLSTATE[42702]: Ambiguous column: 7 ERROR: ORDER BY "created_at" is ambiguous
LINE 1: ...r_id" where "group_user"."group_id" = $1 order by "created_a...
^ (Connection: pgsql, SQL: select "group_user"."group_id" as "pivot_group_id", "group_user"."user_id" as "pivot_user_id", "group_user"."role" as "pivot_role", "group_user"."is_creator" as "pivot_is_creator", "group_user"."current_meal_type_id" as "pivot_current_meal_type_id", "group_user"."created_at" as "pivot_created_at", "group_user"."updated_at" as "pivot_updated_at", "group_user".*, "users".* from "users" inner join "group_user" on "users"."id" = "group_user"."user_id" where "group_user"."group_id" = 4 order by "created_at" asc limit 10 offset 0) {"view":{"view":"/Users/kaspernowak/development/meinrad/meinrad_laravel/filament/packages/tables/resources/views/index.blade.php","data":[]},"userId":6,"exception":"[object] (Spatie\\LaravelIgnition\\Exceptions\\ViewException(code: 0): SQLSTATE[42702]: Ambiguous column: 7 ERROR: ORDER BY \"created_at\" is ambiguous
LINE 1: ...r_id\" where \"group_user\".\"group_id\" = $1 order by \"created_a...
How do I make sure that the table uses the created_at column from the users table when sorting?
19 replies
FFilament
Created by nowak on 9/4/2024 in #❓┊help
Is it possible to add a TextAreainput column to tables?
It seems like it is only possible to add a TextInput column to tables, but is it possible to add a TextArea input column somehow? And if not, why not?
3 replies
FFilament
Created by nowak on 8/31/2024 in #❓┊help
Did the mount() method get removed from Widgets?
I am using the #google-maps plugin where I have created a "custom" MapWidget, which used to update whenever the data was updated, but now this does not work anymore. So I found out that the mount() method in the vendor/cheesegrits/filament-google-maps/src/Widgets/MapWidget.php class is not being triggered anymore, and thought that this might be related to a recent Filament update affecting this, since this used to work. So should this method:
public function mount()
{
$this->dataChecksum = md5('{}');
}
public function mount()
{
$this->dataChecksum = md5('{}');
}
still fire in classes that extend the Widgets\Widget class? Or is this no longer the case?
4 replies
FFilament
Created by nowak on 8/28/2024 in #❓┊help
How to set default date in DatePicker form field in filtersForm?
I have a custom dashboard class, where I want to add a filtersForm, with a date field that should default to todays date (now()), but the default is never being set in my form when I try to do this:
<?php

namespace App\Filament\Pages;

use App\Models\MealType;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Pages\Dashboard as BaseDashboard;

class Dashboard extends BaseDashboard
{

use BaseDashboard\Concerns\HasFiltersForm;
protected static ?string $navigationIcon = 'heroicon-o-document-text';

public function filtersForm(Form $form): Form
{
return $form
->schema([
Section::make()
->schema([
DatePicker::make('deliveryDate')
->default(now()),
Select::make('mealType')
->options(fn() => MealType::all()
->sortBy('id')
->where('is_visible','true')
->pluck('name', 'id')
->map(function ($name) {
return ucfirst($name);
})
)
->default(2)
->selectablePlaceholder(false)
->native(false)
])
->columns(2),
]);
}
}
<?php

namespace App\Filament\Pages;

use App\Models\MealType;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Pages\Dashboard as BaseDashboard;

class Dashboard extends BaseDashboard
{

use BaseDashboard\Concerns\HasFiltersForm;
protected static ?string $navigationIcon = 'heroicon-o-document-text';

public function filtersForm(Form $form): Form
{
return $form
->schema([
Section::make()
->schema([
DatePicker::make('deliveryDate')
->default(now()),
Select::make('mealType')
->options(fn() => MealType::all()
->sortBy('id')
->where('is_visible','true')
->pluck('name', 'id')
->map(function ($name) {
return ucfirst($name);
})
)
->default(2)
->selectablePlaceholder(false)
->native(false)
])
->columns(2),
]);
}
}
I have attached screenshots of my form field when null (on page load) and when I select a date. Does anyone know how I can set the default date correctly?
3 replies
FFilament
Created by nowak on 8/22/2024 in #❓┊help
Slow action modal opening times on resource table
I have a GroupOrderManagementResource with a table, which has actions that use my GroupOrder model records in it's functions. Opening these actions seems to take too long (3+ secons), and I was wondering if I am doing something inefficiently when it comes to using the Resource model records in the table? So my Resource setup looks like this:
class GroupOrderManagementResource extends Resource
{
protected static ?string $model = GroupOrder::class;
protected static ?string $navigationLabel = 'Group Order Manager';

public static ?string $title = 'Group Order Management';

public static ?string $slug = 'group-order-management';
class GroupOrderManagementResource extends Resource
{
protected static ?string $model = GroupOrder::class;
protected static ?string $navigationLabel = 'Group Order Manager';

public static ?string $title = 'Group Order Management';

public static ?string $slug = 'group-order-management';
Then I define my table query like this:
public static function table(Table $table): Table
{
return $table
->query(GroupOrderResource::getEloquentQuery()->with([
'userOrders.userOrderItems.productSku.product.category' => function ($query) {
$query->select('id', 'name');
},
'userOrders.userOrderItems.productSku.product.type' => function ($query) {
$query->select('id', 'name');
},
'route'
])->activeDayGroupOrders())
public static function table(Table $table): Table
{
return $table
->query(GroupOrderResource::getEloquentQuery()->with([
'userOrders.userOrderItems.productSku.product.category' => function ($query) {
$query->select('id', 'name');
},
'userOrders.userOrderItems.productSku.product.type' => function ($query) {
$query->select('id', 'name');
},
'route'
])->activeDayGroupOrders())
Where I am wondering if I am using eager loading correctly? And finally, I have a note TextColumn, that I have added an action to with a form to add/edit the note for a record:
TextColumn::make('note')
->placeholder(__('Click to add note!'))
->extraAttributes(['class' => 'min-w-36 text-wrap cursor-pointer'])
->toggleable()
->action(
Action::make('edit_note')
->label(false)
->form(fn(GroupOrder $record) => [
Textarea::make('note')
->label(fn (Get $get): string => $get('note') ? __('Edit Note') : __('Add Note'))
->default($record->note)
])
->action(fn(GroupOrder $record, array $data) => $record->update(['note' => $data['note']]))
),
TextColumn::make('note')
->placeholder(__('Click to add note!'))
->extraAttributes(['class' => 'min-w-36 text-wrap cursor-pointer'])
->toggleable()
->action(
Action::make('edit_note')
->label(false)
->form(fn(GroupOrder $record) => [
Textarea::make('note')
->label(fn (Get $get): string => $get('note') ? __('Edit Note') : __('Add Note'))
->default($record->note)
])
->action(fn(GroupOrder $record, array $data) => $record->update(['note' => $data['note']]))
),
Any insight is highly appreciated! Thanks!
27 replies
FFilament
Created by nowak on 8/9/2024 in #❓┊help
Duplicate and missing records/rows when navigating table pages
I was looking for a record in an "Orders" table, that I new existed, and I wasn't able to find it while navigating the 10 record per page table pages. I then set the table to show all records, which revealed the record I was looking for. Also, when navigating between pages, I see the same records on different pages (see screen recording) When setting a filter for the order date, for some reason, the record shows on page 2 when navigating the table pages, and the same records don't appear on different pages. Does anyone know why this is?
2 replies
FFilament
Created by nowak on 7/29/2024 in #❓┊help
What is the best way to check if updated resource attributes have changed in afterSave hook?
I am currently doing this, but it seems inefficient and too verbose:
protected function afterSave(): void
{
$mealType = $this->record;
$request = request()->all();
$originalOrderDeadline = null;
$updatedOrderDeadline = null;

// Decode the JSON snapshot
if (isset($request['components'][0]['snapshot'])) {
$snapshot = json_decode($request['components'][0]['snapshot'], true);

if (isset($snapshot['data']['data'])) {
foreach ($snapshot['data']['data'] as $data) {
if (isset($data['id']) && $data['id'] == $mealType->id) {
$originalOrderDeadline = $data['order_deadline'];
break;
}
}
}
}

// Get the updated order_deadline
if (isset($request['components'][0]['updates']['data.order_deadline'])) {
$updatedOrderDeadline = $request['components'][0]['updates']['data.order_deadline'];
}
}
protected function afterSave(): void
{
$mealType = $this->record;
$request = request()->all();
$originalOrderDeadline = null;
$updatedOrderDeadline = null;

// Decode the JSON snapshot
if (isset($request['components'][0]['snapshot'])) {
$snapshot = json_decode($request['components'][0]['snapshot'], true);

if (isset($snapshot['data']['data'])) {
foreach ($snapshot['data']['data'] as $data) {
if (isset($data['id']) && $data['id'] == $mealType->id) {
$originalOrderDeadline = $data['order_deadline'];
break;
}
}
}
}

// Get the updated order_deadline
if (isset($request['components'][0]['updates']['data.order_deadline'])) {
$updatedOrderDeadline = $request['components'][0]['updates']['data.order_deadline'];
}
}
4 replies