Tieme
Tieme
FFilament
Created by Tieme on 10/19/2024 in #❓┊help
Import, before action
For now i use the before action on the importAction
->before(function () {
Staffelprijzen::query()->delete();
}),
->before(function () {
Staffelprijzen::query()->delete();
}),
Not as reliable as i want, but does the job.
3 replies
FFilament
Created by Tieme on 8/14/2024 in #❓┊help
Apply ->translateLabel() everywhere
Totaly forgot about configureUsing]
5 replies
FFilament
Created by Tieme on 8/3/2024 in #❓┊help
2 "save" actions on CreateResource with "mutateFormDataBeforeCreate"
Here is the solution. Create a Formfield, hide the label and add hidden as extraAttributes
Forms\Components\ToggleButtons::make('status')
->options(InternalProjectStatus::class)
->label(false)
->dehydrated(true)
->columnSpan('full')
->default(fn () => InternalProjectStatus::LOCKED)
->extraAttributes([
'class' => 'hidden',
]),
Forms\Components\ToggleButtons::make('status')
->options(InternalProjectStatus::class)
->label(false)
->dehydrated(true)
->columnSpan('full')
->default(fn () => InternalProjectStatus::LOCKED)
->extraAttributes([
'class' => 'hidden',
]),
For the action, set submit to null and update the $livewire->data['status'] in action and than create the record. This will set status to Concept in my case.
protected function getCreateConceptFormAction(): Action
{
return Action::make('concept')
->label(Helpers::translate('Save as concept'))
->color(Color::Blue->getColor())
->submit(null)
->action(function ($livewire) {
$livewire->data['status'] = InternalProjectStatus::CONCEPT;
$this->create();
})
->successNotification(
Notifications\Notification::make()
->success()
->title('Order saves as concept'),
)
->keyBindings(['mod+s']);
}
protected function getCreateConceptFormAction(): Action
{
return Action::make('concept')
->label(Helpers::translate('Save as concept'))
->color(Color::Blue->getColor())
->submit(null)
->action(function ($livewire) {
$livewire->data['status'] = InternalProjectStatus::CONCEPT;
$this->create();
})
->successNotification(
Notifications\Notification::make()
->success()
->title('Order saves as concept'),
)
->keyBindings(['mod+s']);
}
If there is another way i would love to see it. Because this works, but dont think this is the best way of doing this.
11 replies
FFilament
Created by Tieme on 8/3/2024 in #❓┊help
2 "save" actions on CreateResource with "mutateFormDataBeforeCreate"
Damn, did not think about that! Thanks, that will do the trick!
11 replies
FFilament
Created by Tieme on 8/3/2024 in #❓┊help
2 "save" actions on CreateResource with "mutateFormDataBeforeCreate"
So i need to duplicate the create function to only change 1 attribute that needs to be changed? Just like below where i added the $data['status'] = InternalProjectStatus::CONCEPT->value; Isent there a better way to do this?
Action::make('createConcept')
->label('Create Concept')
->submit('createConcept')
->keyBindings(['mod+s']);

public function createConcept(bool $another = false): void
{
$this->authorizeAccess();

try {
$this->beginDatabaseTransaction();

$this->callHook('beforeValidate');

$data = $this->form->getState();

$this->callHook('afterValidate');

$data = $this->mutateFormDataBeforeCreate($data);
$data['status'] = InternalProjectStatus::CONCEPT->value;

$this->callHook('beforeCreate');

$this->record = $this->handleRecordCreation($data);

$this->form->model($this->getRecord())->saveRelationships();

$this->callHook('afterCreate');

$this->commitDatabaseTransaction();
} catch (Halt $exception) {
$exception->shouldRollbackDatabaseTransaction() ?
$this->rollBackDatabaseTransaction() :
$this->commitDatabaseTransaction();

return;
} catch (Throwable $exception) {
$this->rollBackDatabaseTransaction();

throw $exception;
}

$this->rememberData();

$this->getCreatedNotification()?->send();

if ($another) {
// Ensure that the form record is anonymized so that relationships aren't loaded.
$this->form->model($this->getRecord()::class);
$this->record = null;

$this->fillForm();

return;
}

$redirectUrl = $this->getRedirectUrl();

$this->redirect($redirectUrl, navigate: FilamentView::hasSpaMode() && is_app_url($redirectUrl));
}
Action::make('createConcept')
->label('Create Concept')
->submit('createConcept')
->keyBindings(['mod+s']);

public function createConcept(bool $another = false): void
{
$this->authorizeAccess();

try {
$this->beginDatabaseTransaction();

$this->callHook('beforeValidate');

$data = $this->form->getState();

$this->callHook('afterValidate');

$data = $this->mutateFormDataBeforeCreate($data);
$data['status'] = InternalProjectStatus::CONCEPT->value;

$this->callHook('beforeCreate');

$this->record = $this->handleRecordCreation($data);

$this->form->model($this->getRecord())->saveRelationships();

$this->callHook('afterCreate');

$this->commitDatabaseTransaction();
} catch (Halt $exception) {
$exception->shouldRollbackDatabaseTransaction() ?
$this->rollBackDatabaseTransaction() :
$this->commitDatabaseTransaction();

return;
} catch (Throwable $exception) {
$this->rollBackDatabaseTransaction();

throw $exception;
}

$this->rememberData();

$this->getCreatedNotification()?->send();

if ($another) {
// Ensure that the form record is anonymized so that relationships aren't loaded.
$this->form->model($this->getRecord()::class);
$this->record = null;

$this->fillForm();

return;
}

$redirectUrl = $this->getRedirectUrl();

$this->redirect($redirectUrl, navigate: FilamentView::hasSpaMode() && is_app_url($redirectUrl));
}
11 replies
FFilament
Created by Tieme on 8/3/2024 in #❓┊help
2 "save" actions on CreateResource with "mutateFormDataBeforeCreate"
I have that implemented, But don't know how to mutate the data for the "getCreateConceptFormAction"
protected function getFormActions(): array
{
return [
$this->getCreateFormAction()
->keyBindings(false)
->requiresConfirmation()
->label(Helpers::translate('Place Order')),
$this->getCreateConceptFormAction(), // Todo :: figure out how to do this.
$this->getCancelFormAction(),
];
}

// Todo : not working...
protected function getCreateConceptFormAction(): Action
{
return Action::make('createConcept')
->label('Create Concept')
->action(function (array $data) {
$data = $this->mutateFormDataBeforeCreate($data);
$data['status'] = InternalProjectStatus::CONCEPT->value;
dd($data);
static::getModel()::create($data);
})
->model(static::getModel())
->form(fn ($livewire) => static::getResource()::form(new Form($livewire)));

// return Action::make('create')
// //->label(__('filament-panels::resources/pages/create-record.form.actions.create.label'))
// ->label(Helpers::translate('Save as concept'))
// ->color(Color::Blue->getColor())
// ->submit('create')
// ->successNotification(
// Notifications\Notification::make()
// ->success()
// ->title('Order saves as concept'),
// )
// ->keyBindings(['mod+s']);
}
protected function getFormActions(): array
{
return [
$this->getCreateFormAction()
->keyBindings(false)
->requiresConfirmation()
->label(Helpers::translate('Place Order')),
$this->getCreateConceptFormAction(), // Todo :: figure out how to do this.
$this->getCancelFormAction(),
];
}

// Todo : not working...
protected function getCreateConceptFormAction(): Action
{
return Action::make('createConcept')
->label('Create Concept')
->action(function (array $data) {
$data = $this->mutateFormDataBeforeCreate($data);
$data['status'] = InternalProjectStatus::CONCEPT->value;
dd($data);
static::getModel()::create($data);
})
->model(static::getModel())
->form(fn ($livewire) => static::getResource()::form(new Form($livewire)));

// return Action::make('create')
// //->label(__('filament-panels::resources/pages/create-record.form.actions.create.label'))
// ->label(Helpers::translate('Save as concept'))
// ->color(Color::Blue->getColor())
// ->submit('create')
// ->successNotification(
// Notifications\Notification::make()
// ->success()
// ->title('Order saves as concept'),
// )
// ->keyBindings(['mod+s']);
}
11 replies
FFilament
Created by ddoddsr on 7/2/2024 in #❓┊help
Why is my $record->save(); not working
in your case if you want to update the model you need to do
Action::make('Pause Campaign')
->action(function (?Model $record) {
$record->status_id = CampaignStatusEnum::Paused;
$record->save();
})
Action::make('Pause Campaign')
->action(function (?Model $record) {
$record->status_id = CampaignStatusEnum::Paused;
$record->save();
})
10 replies
FFilament
Created by astronomic on 4/29/2024 in #❓┊help
Doubts with summarize(Count)
No description
21 replies
FFilament
Created by jepewsykes on 5/5/2024 in #❓┊help
custom field appends error when sum using summariz
i think you need a query for that. Summarize does a query to the database, that is why it is not working. https://filamentphp.com/docs/3.x/tables/summaries#scoping-the-dataset ->query(fn (Builder $query) => $query->where('is_published', true))
4 replies
FFilament
Created by astronomic on 4/29/2024 in #❓┊help
Doubts with summarize(Count)
Have you read the docs (https://filamentphp.com/docs/3.x/tables/summaries)?
Tables\Columns\TextColumn::make('type')
->label('Tipo')
->summarize(
Count::make('uno')->label('Nº total de clientes')->query(fn ($query) => $query),
Count::make()->label('Nº total de ayuntamientos')->query(fn ($query) => $query->where('type', 0)),
Count::make()->label('Nº total de NO ayuntamientos')->query(fn ($query) => $query->where('type', 1)),
)
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('type')
->label('Tipo')
->summarize(
Count::make('uno')->label('Nº total de clientes')->query(fn ($query) => $query),
Count::make()->label('Nº total de ayuntamientos')->query(fn ($query) => $query->where('type', 0)),
Count::make()->label('Nº total de NO ayuntamientos')->query(fn ($query) => $query->where('type', 1)),
)
->sortable()
->searchable(),
21 replies
FFilament
Created by KingStalker on 5/2/2024 in #❓┊help
widget doesin't update when i use the filter on a table help please
3 replies
FFilament
Created by Jon Mason on 5/2/2024 in #❓┊help
is it possible to add dividers in a grouped action blade / livewire component?
Yes this it possible. You can checkout all the code of fillament on Github and start looking how it should be done, Below is the code you can find in https://github.com/filamentphp/filament/blob/2f5ac6078d522672a437b56d573a78ecf869a67a/docs-assets/app/resources/views/livewire/actions.blade.php#L106-L114
<x-filament-actions::group
:actions="[
\Filament\Actions\ActionGroup::make([
\Filament\Actions\Action::make('view'),
\Filament\Actions\Action::make('edit'),
])->dropdown(false),
\Filament\Actions\Action::make('delete'),
]"
/>
<x-filament-actions::group
:actions="[
\Filament\Actions\ActionGroup::make([
\Filament\Actions\Action::make('view'),
\Filament\Actions\Action::make('edit'),
])->dropdown(false),
\Filament\Actions\Action::make('delete'),
]"
/>
4 replies
FFilament
Created by Expecto Patronum on 5/3/2024 in #❓┊help
Versionable By Mansoor Khan
3 replies
FFilament
Created by warpig on 5/3/2024 in #❓┊help
installing version 3
Restart you computer, after you changed the php.ini php needs to restart before changed apply.
7 replies
FFilament
Created by big010_ on 5/1/2024 in #❓┊help
Filament Serial Number generator
4 replies
FFilament
Created by Expecto Patronum on 5/3/2024 in #❓┊help
Use 1 attribute for 2 SelectFilter
You cant use same "id's" with filter. you need to change one "product_id" to somethin like "product_name" and than set a attribute "product_id" https://filamentphp.com/docs/3.x/tables/filters/select#customizing-the-column-used-by-a-select-filter
3 replies
FFilament
Created by Wally on 5/3/2024 in #❓┊help
Attachments concept tips
Depends on more than that. i have a applications where 2 models have a total of 3 images per record. I defined the imaged in that model. Als other applications where almost all models / records can have attachments. There i have a morph to.
4 replies
FFilament
Created by Darkavatar23 on 5/3/2024 in #❓┊help
Image Gallery On Modal like ImageColumn
Maybe a litle detour to a CheckboxList? Here you can create the options with a image as description https://filamentphp.com/docs/3.x/forms/fields/checkbox-list#setting-option-descriptions
5 replies
FFilament
Created by Noor on 5/2/2024 in #❓┊help
Data is not getting saved in db after tranferring one form data to another
Hi, first a sidenote, please don't use route when creating a url to a resource. Read the following https://filamentphp.com/docs/3.x/panels/resources/getting-started#generating-urls-to-resource-pages Are you getting any errors? Is your form populated with all the data you want? Because what you are doing is not changing data before safe you need to use https://filamentphp.com/docs/3.x/panels/resources/creating-records#customizing-data-before-saving for that. Your action is before filling the form, so is the form populated with data?
5 replies
FFilament
Created by Soundmit on 5/3/2024 in #❓┊help
Hidden field works only while create and not edit
@Soundmit i hade the same issue. I have cast on the model and use a "helper function" so it will work on create and edit form sidenote : All my enums are numeric so possible the code can be optimzed to meet you needs. Somethin like instance of enum
class Helpers{

/**
* Retrieves the value from an enumeration.
*
* @param mixed $enum The enumeration value.
* @return mixed The value from the enumeration.
*/
public static function getValueFromEnum(mixed $enum)
{
if (is_numeric($enum) or is_null($enum)) {
return $enum;
}

return $enum->value;
}

}

->visible(fn ( Get $get) => Helpers::getValueFromEnum($get('customer_type')) === CustomerType::BUSINESS->value)
class Helpers{

/**
* Retrieves the value from an enumeration.
*
* @param mixed $enum The enumeration value.
* @return mixed The value from the enumeration.
*/
public static function getValueFromEnum(mixed $enum)
{
if (is_numeric($enum) or is_null($enum)) {
return $enum;
}

return $enum->value;
}

}

->visible(fn ( Get $get) => Helpers::getValueFromEnum($get('customer_type')) === CustomerType::BUSINESS->value)
11 replies