nowak
nowak
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?
After looking into this again, I thought that it was weird that the native CreateAction didn't work. So I tried to add this to the List page instead:
protected function getHeaderActions(): array
{
return [
CreateAction::make('userOrder')
->label('Create User Order')
->model(UserOrder::class)
->form(UserOrderResource::getFormSchema())
->fillForm([
'user_id' => User::firstWhere(
'email',
config('meinrad.assistant_email')
)->id
])
->mutateFormDataUsing(function (array $data): array {
$mealType = MealType::find($data['meal_type_id']);
$deliveryDate = Carbon::createFromFormat(
'Y-m-d',
$data['delivery_date']
);
$orderDeadlineTime = Carbon::createFromFormat(
'H:i:s',
$mealType->order_deadline
);
$deadline = $deliveryDate->setTime(
$orderDeadlineTime->hour,
$orderDeadlineTime->minute,
$orderDeadlineTime->second
);
$data['deadline'] = $deadline->toDateTimeString();
return $data;
})
->after(function ($record) {
$detailCreator = app(CreatesUserOrderDetails::class);
$detailCreator->create($record);
$groupOrderCreator = app(CreatesGroupOrders::class);
$groupOrder = $groupOrderCreator->create($record);
if ($groupOrder) {
$updater = app(UpdatesGroupOrders::class);
$updater->update($groupOrder, []);
}
}),
];
}
protected function getHeaderActions(): array
{
return [
CreateAction::make('userOrder')
->label('Create User Order')
->model(UserOrder::class)
->form(UserOrderResource::getFormSchema())
->fillForm([
'user_id' => User::firstWhere(
'email',
config('meinrad.assistant_email')
)->id
])
->mutateFormDataUsing(function (array $data): array {
$mealType = MealType::find($data['meal_type_id']);
$deliveryDate = Carbon::createFromFormat(
'Y-m-d',
$data['delivery_date']
);
$orderDeadlineTime = Carbon::createFromFormat(
'H:i:s',
$mealType->order_deadline
);
$deadline = $deliveryDate->setTime(
$orderDeadlineTime->hour,
$orderDeadlineTime->minute,
$orderDeadlineTime->second
);
$data['deadline'] = $deadline->toDateTimeString();
return $data;
})
->after(function ($record) {
$detailCreator = app(CreatesUserOrderDetails::class);
$detailCreator->create($record);
$groupOrderCreator = app(CreatesGroupOrders::class);
$groupOrder = $groupOrderCreator->create($record);
if ($groupOrder) {
$updater = app(UpdatesGroupOrders::class);
$updater->update($groupOrder, []);
}
}),
];
}
Which works, but I have to add mutateFormDataUsing and after logic, as this is not inherited from the UserOrderResource Create page. So this action would be added to the page header instead of the table header, which is also a con, but CreateAction() just doesn't work from a tables headerActions([]) for some good reason probably. @ChesterS Maybe useful for you as well?
23 replies
FFilament
Created by ericmp on 10/25/2024 in #❓┊help
Sort table by random order
example:
15 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 had to use this as well I think:
php artisan filament:optimize-clear
php artisan filament:optimize-clear
Are you saying this wasn't necessary?
25 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
Should this be ran on every deploy?
25 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
Yes! I found this:
'app.filament.pages.dashboard' => 'App\\Filament\\Pages\\Dashboard',
'app.filament.pages.dashboard' => 'App\\Filament\\Pages\\Dashboard',
in /bootstrap/cache/filament/panels/admin.php What is the recommended way of clearing this cache?
25 replies
FFilament
Created by ericmp on 10/25/2024 in #❓┊help
Sort table by random order
Okay, I got curious so I added a 2000 song table to a fresh filament installation and did some experimenting. got it to work by using baseQuery instead of query (https://filamentphp.com/docs/3.x/tables/filters/getting-started#modifying-the-base-query) :
->filters([
Filter::make('Shuffle')
->toggle()
->baseQuery(fn (Builder $query) => $query->inRandomOrder())
->label('Shuffle Songs'),
])
->filters([
Filter::make('Shuffle')
->toggle()
->baseQuery(fn (Builder $query) => $query->inRandomOrder())
->label('Shuffle Songs'),
])
15 replies
FFilament
Created by ericmp on 10/25/2024 in #❓┊help
Sort table by random order
Are you showing thousands of songs at once? You could just shuffle the songs shown in the current view. I don't know how expensive it would be to shuffle all songs in the database, might be worth trying out, though
15 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
Still weird that I have no issues on my local environment, only on my remote server do I get this error.
25 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 removed KitchenDashboard from my admin panel provider pages as this wasn't necessary on a fresh filament installation, and changed to:
use HasFiltersForm;
use HasFiltersForm;
I get the same ish error still:
include(/home/www/appstaging.meinrad.ch/app/Filament/Pages/Dashboard.php): Failed to open stream: No such file or directory
include(/home/www/appstaging.meinrad.ch/app/Filament/Pages/Dashboard.php): Failed to open stream: No such file or directory
Here is my flare error: https://flareapp.io/share/bP9oYg85
25 replies
FFilament
Created by ericmp on 10/25/2024 in #❓┊help
Sort table by random order
This is basically what the filament reorder functionality does, but one by one.
15 replies
FFilament
Created by ericmp on 10/25/2024 in #❓┊help
Sort table by random order
I think what you need to do, is to add a sorting column to your songs table, that you can use to: 1. Sort the records by in the table 2. Use a custom table header action to "randomly" shuffle the sort integers of your song records Then when you trigger your "Randomize" action, the sort would be shuffled, and your song records would appear to be shuffled as well as a result.
15 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 did 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;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
use App\Filament\Widgets;

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';
.......
<?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;
use App\Filament\Widgets;

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';
.......
25 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 do have this route in my routes/web.php file:
Route::get('/dashboard', function () {
return redirect()->route('home');
})->name('dashboard');
Route::get('/dashboard', function () {
return redirect()->route('home');
})->name('dashboard');
Which I use for my inertia frontend. Maybe this has something to do with it?
25 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 just tried to add to add my new dashboard to ->pages() like this:
->pages([
KitchenDashboard::class,
])
->pages([
KitchenDashboard::class,
])
And I still get the error: Class "App\Filament\Pages\Dashboard" not found But I just don't understand where filament gets App\Filament\Pages\Dashboard from, as I don't have that in my code anywhere 🤔 Here is a shared flare of my error, it seems to have something to do with routes: https://flareapp.io/share/LPd0G9dP
25 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?
Will do!
23 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?
Ahh, I get it.
23 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?
So I could basically use this page here:
class CreateUserOrder extends CreateRecord
class CreateUserOrder extends CreateRecord
23 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?
Interesting, what is your CreatOrderForProperty::class exactly?
23 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?
The detail relationship is on the UserOrder model though:
public function detail()
{
return $this->hasOne(UserOrderDetail::class);
}
public function detail()
{
return $this->hasOne(UserOrderDetail::class);
}
My approach is that I have a GroupOrderResource, where I manage all GroupOrders (add couriers, set routes etc.) directly on the table. All UserOrders belong to a GroupOrder, and what I want to do, is add an action on this table, where I can easily create a new UserOrder. I know I could edit a GroupOrder -> UserOrder relations -> Create. But that is a few clicks and loading away, and if a GroupOrder does not exist yet, I can't use this approach (a GroupOrder is created after an initial UserOrder is created). So having an action to create a UserOrder directly on the GroupOrderResource would be very helpful.
23 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 am only using resources. Where this header action on the GroupOrderResource:
->headerActions([
\Filament\Tables\Actions\Action::make('userOrder')
->model(UserOrder::class)
->form(UserOrderResource::getFormSchema()),
)]
->headerActions([
\Filament\Tables\Actions\Action::make('userOrder')
->model(UserOrder::class)
->form(UserOrderResource::getFormSchema()),
)]
Gives me this error:
Call to undefined method App\Models\GroupOrder::detail()
Call to undefined method App\Models\GroupOrder::detail()
Because my Form Schema in UserOrderResource has this form component:
Grid::make('Detail')
->relationship('detail')
->hidden(condition: fn (Get $get, ?Model $record) => !$record || User::find($get('user_id')))
->schema([
TextInput::make('name_label')
->label('User')
->disabled(),
]),
Grid::make('Detail')
->relationship('detail')
->hidden(condition: fn (Get $get, ?Model $record) => !$record || User::find($get('user_id')))
->schema([
TextInput::make('name_label')
->label('User')
->disabled(),
]),
Which is strange, as I pass the ->model(UserOrder::class)
23 replies