DarkCoder
DarkCoder
FFilament
Created by DarkCoder on 6/9/2024 in #❓┊help
Unable to use tabs in listview. trim(): Argument #1 ($string) must be of type string, Filament\Suppo
No description
2 replies
FFilament
Created by DarkCoder on 6/2/2024 in #❓┊help
Use value from parent model as default in attachAction relationmanager
I have a Service Model and a Doctor Model, and a ServiceDoctor Pivot Table. I am using a relation manager to attach Doctors to Services. The Pivot Table also has some extra fields like price and time. The service table also have fields named default_price and default_time I want to attach action to set the default values during attachment. Is this possible?
class DoctorRelationManager extends RelationManager
{
protected static string $relationship = 'doctors';

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('first_name')
->required()
->maxLength(255),
]);
}

public function table(Table $table): Table
{
return $table
->recordTitleAttribute('first_name')
->columns([
Tables\Columns\TextColumn::make('first_name'),
Tables\Columns\TextColumn::make('price'),
Tables\Columns\TextColumn::make('price_online'),
Tables\Columns\TextColumn::make('time'),
])
->filters([
//
])
->headerActions([
Tables\Actions\AttachAction::make()
->preloadRecordSelect()
->form(fn (Tables\Actions\AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\TextInput::make('price')
->numeric()
->required()
->label("Price Offline (0 if not provided)")
->default(function () use ($action) {
return $action->parent?->default_price; // I want the default_price to be pulled from the parent Service class
}),
...
]),
])
->actions([
Tables\Actions\DetachAction::make(),
]);
}
}
class DoctorRelationManager extends RelationManager
{
protected static string $relationship = 'doctors';

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('first_name')
->required()
->maxLength(255),
]);
}

public function table(Table $table): Table
{
return $table
->recordTitleAttribute('first_name')
->columns([
Tables\Columns\TextColumn::make('first_name'),
Tables\Columns\TextColumn::make('price'),
Tables\Columns\TextColumn::make('price_online'),
Tables\Columns\TextColumn::make('time'),
])
->filters([
//
])
->headerActions([
Tables\Actions\AttachAction::make()
->preloadRecordSelect()
->form(fn (Tables\Actions\AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\TextInput::make('price')
->numeric()
->required()
->label("Price Offline (0 if not provided)")
->default(function () use ($action) {
return $action->parent?->default_price; // I want the default_price to be pulled from the parent Service class
}),
...
]),
])
->actions([
Tables\Actions\DetachAction::make(),
]);
}
}
4 replies
FFilament
Created by DarkCoder on 3/15/2024 in #❓┊help
Throwing ValidationException from afterStateUpdated
Hi, is it possible to throw a ValidationException from the afterStateUpdated lifehook on a form field? Is there any other way to do it using halts?
>afterStateUpdated(function ($state, Get $get, callable $set) {
if($pivotData->isValidTimeSlot($state)){
// Do something
else{
throw ValidationException::withMessages(['start_datetime' => 'Datetime is invalid']);
}
}
>afterStateUpdated(function ($state, Get $get, callable $set) {
if($pivotData->isValidTimeSlot($state)){
// Do something
else{
throw ValidationException::withMessages(['start_datetime' => 'Datetime is invalid']);
}
}
But this doesnt seem to work. I can send Notifications but I want the validation error to trigger
3 replies
FFilament
Created by DarkCoder on 3/13/2024 in #❓┊help
Equivalent of UpdateOrCreate
Hello, I want the createAction to check if a record already exists and then update it instead of creating a new entry everytime. I've thought about using handleRecordCreation() but it creates a new record anyway.
4 replies
FFilament
Created by DarkCoder on 3/11/2024 in #❓┊help
Auto Creating Child Model from Parent Resource
Hello, I have two Resources/modes, Appointment and Client Every appointment has a BelongsTo relation called client() Clients have hasMany appointments. I created the resources with --generate, and on the appointments create page, I can only put in the details of the appointment and choose an existing client from a select box. However, I want to create the client while Im creating the appointment. In other words, I want the fields of client creation to be shown in the appointment creation page, and on submit filament should first create the client, and then automatically handle the relationship. I have tried relationshipmanager and it only works for editing and viewing but not creating. I have tried to add the client fields manually
class AppointmentResource extends Resource
{
...

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Fieldset::make('Client')
->relationship('client')
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('phone_number')
->tel()
->required()
->maxLength(255),
...
]),
Forms\Components\DateTimePicker::make('start_datetime')
->required(),
Forms\Components\DateTimePicker::make('end_datetime')
->required(),
...
class AppointmentResource extends Resource
{
...

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Fieldset::make('Client')
->relationship('client')
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('phone_number')
->tel()
->required()
->maxLength(255),
...
]),
Forms\Components\DateTimePicker::make('start_datetime')
->required(),
Forms\Components\DateTimePicker::make('end_datetime')
->required(),
...
but it gives an error that client_id is required Is this possible?
1 replies