Ric Le Poidevin
Ric Le Poidevin
FFilament
Created by Ric Le Poidevin on 3/21/2024 in #❓┊help
Validate and save before opening modal
I have an edit page with a header action that opens a modal. I need to save (and validate) the current record before opening modal as it depends on that data being saved as it’s a publish action. The form I need to save is a wizard if that makes any difference. My header action:
\Filament\Actions\Action::make('Publish!')
// Validate and save current record, then open modal if it passed, or cancel if validation fails
->closeModalByClickingAway(false)
->slideOver()
->form([
VacancyPayment::make('Publish details'),
])
->modalSubmitAction(false)
->modalCancelActionLabel('Close')
->stickyModalFooter(false),
\Filament\Actions\Action::make('Publish!')
// Validate and save current record, then open modal if it passed, or cancel if validation fails
->closeModalByClickingAway(false)
->slideOver()
->form([
VacancyPayment::make('Publish details'),
])
->modalSubmitAction(false)
->modalCancelActionLabel('Close')
->stickyModalFooter(false),
2 replies
FFilament
Created by Ric Le Poidevin on 3/8/2024 in #❓┊help
How to hide null relationships on table
I have a Table showing Applications for Vacancies (Vacancies HasMany Applications and Applications BelongsTo a Vacancy). When Vacancies are deleted, any Applications have their relation set to null - this is so the person posting a Vacancy can’t delete an Application by another user. I want to try two things: First idea, how do I filter Applications will a null Vacancy relation? Here’s my current code for show all Applications and their Vacancy
// ApplicationResource
$table
->columns([
Tables\Columns\TextColumn::make('title')
->searchable(),
Tables\Columns\TextColumn::make('vacancy.title')
->url(fn (Application $application): string => VacancyResource::getUrl('edit', ['record' => $application->vacancy_id])),
Tables\Columns\TextColumn::make('created_at')
->label('Received')
->dateTime(),
])
...
// ApplicationResource
$table
->columns([
Tables\Columns\TextColumn::make('title')
->searchable(),
Tables\Columns\TextColumn::make('vacancy.title')
->url(fn (Application $application): string => VacancyResource::getUrl('edit', ['record' => $application->vacancy_id])),
Tables\Columns\TextColumn::make('created_at')
->label('Received')
->dateTime(),
])
...
Second idea - how can I display ‘Deleted vacancy’ if the relationship is null
2 replies
FFilament
Created by Ric Le Poidevin on 3/5/2024 in #❓┊help
Prohibits on Checkbox not working
No description
4 replies
FFilament
Created by Ric Le Poidevin on 3/1/2024 in #❓┊help
On Selects is it possible to make the createOptionForm button clearer
No description
11 replies
FFilament
Created by Ric Le Poidevin on 12/13/2023 in #❓┊help
How to get current record on Table action using a custom form field
Hi, I have a Resource with a Table action using a custom field. I need pass data to the view for this action - all works well for user details but how do I pass the current record’s ID? I’ve tried lots of approaches but it never passes the data
// Resource class action $table actions
Tables\Actions\Action::make('Publish')
->form([
BraintreePayment::make('Billing details')
->viewData([
'first_name' => auth()->user()->first_name,
...
'payment' => [
'type' => 'publish',
// 'record_id' => fn (Model $record) => $record,
'record_id' => fn ($form) => $form->getRecord(), // $record->id,
]
])
])
// Resource class action $table actions
Tables\Actions\Action::make('Publish')
->form([
BraintreePayment::make('Billing details')
->viewData([
'first_name' => auth()->user()->first_name,
...
'payment' => [
'type' => 'publish',
// 'record_id' => fn (Model $record) => $record,
'record_id' => fn ($form) => $form->getRecord(), // $record->id,
]
])
])
I know I can get the record in my BraintreePayment Blade using recordId: '{{ $getRecord()->id }}' but this doesn’t work for me as I want to pass in an object of data to make the component describing the type of payment being made more reusable for different situations.
3 replies
FFilament
Created by Ric Le Poidevin on 11/29/2023 in #❓┊help
Liveware inputs not updating state
I’ve a custom form component that is not updating the Livewire state. On load the data is correctly initialised and the fields populated. If I use the Alpine JS tools and update a value (green highlight) the input updates. If I update the input (yellow highlight) the state doesn’t update.
<div
x-ignore
ax-load
ax-load-src="{{ \Filament\Support\Facades\FilamentAsset::getAlpineComponentSrc('braintree-payment') }}"
x-data="braintreePayment({
state: {
clientToken: '{{ $clientToken }}',
isLoaded: false,
paymentAttempt: false,
user: {
givenName: '{{ $first_name }}',
surname: '{{ $surname }}'
}
}
})"
>
<div x-show="state.isLoaded && !state.paymentAttempt">
<div>
<x-filament-forms::field-wrapper class="rounded-lg" id="name" required="required" label="Name">
<x-filament::input.wrapper>
<x-filament::input
type="text"
x-bind:value="state.user.givenName"
required
/>
</x-filament::input.wrapper>
</x-filament-forms::field-wrapper>

<x-filament-forms::field-wrapper class="rounded-lg" id="surname" required="required" label="Surname">
<x-filament::input.wrapper>
<x-filament::input
type="text"
x-bind:value="state.user.surname"
required
/>
</x-filament::input.wrapper>
</x-filament-forms::field-wrapper>
<div
x-ignore
ax-load
ax-load-src="{{ \Filament\Support\Facades\FilamentAsset::getAlpineComponentSrc('braintree-payment') }}"
x-data="braintreePayment({
state: {
clientToken: '{{ $clientToken }}',
isLoaded: false,
paymentAttempt: false,
user: {
givenName: '{{ $first_name }}',
surname: '{{ $surname }}'
}
}
})"
>
<div x-show="state.isLoaded && !state.paymentAttempt">
<div>
<x-filament-forms::field-wrapper class="rounded-lg" id="name" required="required" label="Name">
<x-filament::input.wrapper>
<x-filament::input
type="text"
x-bind:value="state.user.givenName"
required
/>
</x-filament::input.wrapper>
</x-filament-forms::field-wrapper>

<x-filament-forms::field-wrapper class="rounded-lg" id="surname" required="required" label="Surname">
<x-filament::input.wrapper>
<x-filament::input
type="text"
x-bind:value="state.user.surname"
required
/>
</x-filament::input.wrapper>
</x-filament-forms::field-wrapper>
import dropIn from "braintree-web-drop-in";

export default function braintreePayment({
state,
}) {
return {
state,

init: function () {
console.log(this.state);
this.state.isLoaded = true;
....
import dropIn from "braintree-web-drop-in";

export default function braintreePayment({
state,
}) {
return {
state,

init: function () {
console.log(this.state);
this.state.isLoaded = true;
....
4 replies
FFilament
Created by Ric Le Poidevin on 11/6/2023 in #❓┊help
Multi-tenancy and createOptionForm on Select, Field 'company_id' doesn't have a default value
I have a resource that takes Contacts as a Select options. I want to add a Create form to the Select to create a new Contact but when saving get the following error: SQLSTATE[HY000]: General error: 1364 Field 'company_id' doesn't have a default value The ContactResource form works when used standalone from the menu, but does not when used as the createOptionForm
Forms\Components\Select::make('Contact')
->label('Send applications to')
->relationship('contacts', 'name')
->createOptionForm(fn(Form $form) => ContactResource::form($form)),
Forms\Components\Select::make('Contact')
->label('Send applications to')
->relationship('contacts', 'name')
->createOptionForm(fn(Form $form) => ContactResource::form($form)),
// the contact resource form

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make()
->schema([
Forms\Components\TextInput::make('name')
->required(),
Forms\Components\TextInput::make('email')
->required(),
Forms\Components\TextInput::make('telephone')
->required(),
Forms\Components\Textarea::make('address')
->required(),
])
->columns(2),
]);
}
// the contact resource form

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make()
->schema([
Forms\Components\TextInput::make('name')
->required(),
Forms\Components\TextInput::make('email')
->required(),
Forms\Components\TextInput::make('telephone')
->required(),
Forms\Components\Textarea::make('address')
->required(),
])
->columns(2),
]);
}
14 replies
FFilament
Created by Ric Le Poidevin on 10/6/2023 in #❓┊help
Best way to manage single record resource?
I have a couple of places where I want single record resources (user settings, company details etc.). What’s the best way to build these? I want to add an item to the menu which goes to either the edit or view page (there is no index page) for the user’s instance of that resource. Each user has a single record, some are shared by tenants. When would the record be created? When saving for the first time? Or can it be created when the user is so it’s ready? I don’t have a prefence either way right now.
4 replies
FFilament
Created by Ric Le Poidevin on 10/5/2023 in #❓┊help
getCurrentPanel returning wrong panel
No description
4 replies
FFilament
Created by Ric Le Poidevin on 9/27/2023 in #❓┊help
SaveFormAction works in footer but not header
How do I get the save button to work when in a header?
class EditVacancy extends EditRecord
{
protected static string $resource = VacancyResource::class;

protected function getHeaderActions(): array
{
return [
$this->getSaveFormAction(), // does not run
];
}

protected function getFormActions(): array
{
return [
$this->getSaveFormAction(),
];
}
}
class EditVacancy extends EditRecord
{
protected static string $resource = VacancyResource::class;

protected function getHeaderActions(): array
{
return [
$this->getSaveFormAction(), // does not run
];
}

protected function getFormActions(): array
{
return [
$this->getSaveFormAction(),
];
}
}
5 replies
FFilament
Created by Ric Le Poidevin on 9/26/2023 in #❓┊help
Save form before running action
Is it possible to validate and save a form before an action it run? I want to ensure all the data is correct and stored but running a publish action.
18 replies
FFilament
Created by Ric Le Poidevin on 9/26/2023 in #❓┊help
Have expiry date depend on publish date value
I’ve two date pickers, a publish date and an expiry date. How can I link the two so the expiry date has to be within 28 days of the publish date? And if a publish day is set, then an earlier date selected, how do I ensure the expiry date is updated to be with the 28 day period? Here’s what I have but I get this error Call to a member function addDays() on string. If a date is already set there is no error but nothing updates live when values are changed.
Forms\Components\DateTimePicker::make('publish_date')
->live()
->prefixIcon('heroicon-o-calendar')
->minDate(now())
->seconds(false)
->minutesStep(5)
->native(false)
->disabled(fn(Vacancy $record) => $record->is_published),
Forms\Components\DatePicker::make('expiry_date')
->prefixIcon('heroicon-o-calendar')
->minDate(now())
// max date should always be 28 more than selected publish date
->maxDate(fn(Get $get) => $get('publish_date')->addDays(28))
->native(false)
Forms\Components\DateTimePicker::make('publish_date')
->live()
->prefixIcon('heroicon-o-calendar')
->minDate(now())
->seconds(false)
->minutesStep(5)
->native(false)
->disabled(fn(Vacancy $record) => $record->is_published),
Forms\Components\DatePicker::make('expiry_date')
->prefixIcon('heroicon-o-calendar')
->minDate(now())
// max date should always be 28 more than selected publish date
->maxDate(fn(Get $get) => $get('publish_date')->addDays(28))
->native(false)
1 replies
FFilament
Created by Ric Le Poidevin on 9/25/2023 in #❓┊help
Prohibits validation rule
I have a form with two fields - only one should be filled, not both. This would use Laravel’s prohibits (https://laravel.com/docs/10.x/validation#rule-prohibits) normally but that is not supported. I found an old post on here saying to do this: ->prohibited(fn (Closure $get): bool => filled($get('field1'))) But when I try this I get the following error: App\Filament\Pages\Tenancy\RegisterCompany::App\Filament\Pages\Tenancy\{closure}(): Argument #1 ($get) must be of type Closure, Filament\Forms\Get given, called in /app/vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 35 Here’s my form - either the select should be selected or the input filled, not both:
<?php
namespace App\Filament\Pages\Tenancy;

use App\Models\Company;
use Closure;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Pages\Tenancy\RegisterTenant;

class RegisterCompany extends RegisterTenant
{
public static function getLabel(): string
{
return 'Add or join company';
}

public function form(Form $form): Form
{

$companies = Company::where('email', 'LIKE', '%' . auth()->user()->email_domain)->get();

$formSchema = [];

if ($companies) {
$formSchema[] = Section::make('Join existing company')->
description('...')->
schema([
Select::make('company_id')->reactive()->options($companies->pluck('name', 'id')->toArray())->prohibited(fn (Closure $get): bool => filled($get('name'))),
]);
}

$formSchema[] = Section::make('Create new company')->
description('...')->
schema([
TextInput::make('name')->reactive()->prohibited(fn (Closure $get): bool => filled($get('company_id'))),
]);

return $form->schema($formSchema);

}
}
<?php
namespace App\Filament\Pages\Tenancy;

use App\Models\Company;
use Closure;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Pages\Tenancy\RegisterTenant;

class RegisterCompany extends RegisterTenant
{
public static function getLabel(): string
{
return 'Add or join company';
}

public function form(Form $form): Form
{

$companies = Company::where('email', 'LIKE', '%' . auth()->user()->email_domain)->get();

$formSchema = [];

if ($companies) {
$formSchema[] = Section::make('Join existing company')->
description('...')->
schema([
Select::make('company_id')->reactive()->options($companies->pluck('name', 'id')->toArray())->prohibited(fn (Closure $get): bool => filled($get('name'))),
]);
}

$formSchema[] = Section::make('Create new company')->
description('...')->
schema([
TextInput::make('name')->reactive()->prohibited(fn (Closure $get): bool => filled($get('company_id'))),
]);

return $form->schema($formSchema);

}
}
2 replies
FFilament
Created by Ric Le Poidevin on 9/20/2023 in #❓┊help
Disable modal submit until criteria met (JS fetch response)
No description
9 replies
FFilament
Created by Ric Le Poidevin on 9/20/2023 in #❓┊help
Custom fields - PHP class to process data?
No description
2 replies
FFilament
Created by Ric Le Poidevin on 9/19/2023 in #❓┊help
Take payments from Actions / Plugins (Braintree)
Hi, I’ve just moved over from Nova and love Filament so far but am stuck. Using V3. I have a requirement to take a payment using Braintree/PayPal (that’s all that is supported where I live ☹️). After payment is taken a database columns needs to be updated. I thought using a Modal Action would be a good way top handle this but I don’t know where to begin loading the Braintree JS library into the modal, then processing and saving the response to upload the database. Any help pointing me in the right direction would be appreciated.
3 replies