Damien
Damien
FFilament
Created by Damien on 4/24/2024 in #❓┊help
How do I make a table column searchable based on its state value?
I have a table column that has a default value of a user_id. However, I format the state to show the users first and last name. Here is the code I have for doing so:
TextColumn::make('client_id')
->label('Client')
->searchable() // TODO: works for id but not the formatted name value ????
->formatStateUsing(function ($state) {
$contact = Contact::where('id', $state)->first();

return $contact->first_name.' '.$contact->last_name;
}),
TextColumn::make('client_id')
->label('Client')
->searchable() // TODO: works for id but not the formatted name value ????
->formatStateUsing(function ($state) {
$contact = Contact::where('id', $state)->first();

return $contact->first_name.' '.$contact->last_name;
}),
If I search using the user id, it works, however what I would like to be able to do is search by the value of the users name. Is there a way to do this with my current code or do I need to do something differently?
12 replies
FFilament
Created by Damien on 4/22/2024 in #❓┊help
How do I access / create relationships in custom actions that uses the createOptionForm method.
I have a custom action, that enables me to create a resource from another resources view. In this instance, I am wanting to create a project from the view contact page. Here is the Step for my action so far:
Step::make('Project')
->schema([
// ...
Select::make('project_type_id')
->label('Project Type')
->columnSpan(6)
->hidden(fn () => ! auth()->user()->hasAdminPrivileges())
->relationship('projectType', 'type')
->createOptionForm([
TextInput::make('type')
->required()
->maxLength(255),
])
->editOptionForm([
TextInput::make('type')
->required()
->maxLength(255),
])
->preload()
->required(),
// ...
])->columns(12),
Step::make('Project')
->schema([
// ...
Select::make('project_type_id')
->label('Project Type')
->columnSpan(6)
->hidden(fn () => ! auth()->user()->hasAdminPrivileges())
->relationship('projectType', 'type')
->createOptionForm([
TextInput::make('type')
->required()
->maxLength(255),
])
->editOptionForm([
TextInput::make('type')
->required()
->maxLength(255),
])
->preload()
->required(),
// ...
])->columns(12),
Here is the error I am getting when trying to create my project Call to a member function isRelation() on null Initially I thought I could create a method within the model to satisfy this but I was wrong. So my question is; how can implement the above so that the isRelation() method is satisfied?
7 replies
FFilament
Created by Damien on 4/18/2024 in #❓┊help
Styling forms modal forms created with createOptionsForm()
No description
18 replies
FFilament
Created by Damien on 4/17/2024 in #❓┊help
Is there a way to prevent soft deleted records appearing in global search?
I have checked the documentation for this but I cannot seem to find if this is a configurable option or not. I would like for records that have been soft deleted, to not be returned by the global search, is this possible?
10 replies
FFilament
Created by Damien on 4/16/2024 in #❓┊help
Is it possible to pre-populate this form with some data?
I have a custom widget, with a heading defined like so:
<div class="flex items-center justify-between">
<p class="font-bold text-xl">Contacts</p>
<x-filament::button tag="a" href="{{
\App\Filament\Resources\ContactResource::getUrl(parameters: [
'action' => \Filament\Actions\CreateAction::getDefaultName()
])
}}">
Add Contact
</x-filament::button>
</div>
<div class="flex items-center justify-between">
<p class="font-bold text-xl">Contacts</p>
<x-filament::button tag="a" href="{{
\App\Filament\Resources\ContactResource::getUrl(parameters: [
'action' => \Filament\Actions\CreateAction::getDefaultName()
])
}}">
Add Contact
</x-filament::button>
</div>
This widget lives on a Company details page, what I would like to do when adding the contact, is to be able to pre-populate some of the information that will come from the company, such as the address. Is this possible with my current implementation or would I have to change to work?
31 replies
FFilament
Created by Damien on 3/26/2024 in #❓┊help
How do I update the view modal state after an edit action?
In the following scenario, I have a CompanyResource and I have the following table actions:
->actions([
Tables\Actions\ViewAction::make()
->modalWidth('lg')
->modalFooterActionsAlignment('end')
->extraModalFooterActions([
Tables\Actions\EditAction::make()
->modalFooterActionsAlignment('end')
->modalWidth('lg'),
]),
Tables\Actions\EditAction::make()
->modalWidth('lg')
->modalFooterActionsAlignment('end'),
])->actionsColumnLabel('Actions')
->actions([
Tables\Actions\ViewAction::make()
->modalWidth('lg')
->modalFooterActionsAlignment('end')
->extraModalFooterActions([
Tables\Actions\EditAction::make()
->modalFooterActionsAlignment('end')
->modalWidth('lg'),
]),
Tables\Actions\EditAction::make()
->modalWidth('lg')
->modalFooterActionsAlignment('end'),
])->actionsColumnLabel('Actions')
At present, when I click a row on the table, it brings up the view modal, I then proceed to click edit, change a value and save. The view modal comes back but it still displays the old name. The table however does update in the background. What is the best way to handle this so that it gives a better UX than what I am currently giving / getting? Apologies if this is covered in the docs, I struggled to find it.
3 replies
FFilament
Created by Damien on 2/8/2024 in #❓┊help
Why does my form `->required()` methods not work inside of a Livewire component?
Hey all, so I am creating a 'Settings' page which has a collection of livewire components. I am trying to use a Radio input and a File upload input like so:
public function form(Form $form): Form
{
return $form
->schema([
FileUpload::make('attachment')
->previewable(false)
->storeFiles(false)
->downloadable()
->required()
->acceptedFileTypes(['text/csv']),
Radio::make('type')
->label('Type of Products')
->options([
'1' => 'Products',
'2' => 'Services',
])
->required(),
])
->statePath('data');
}
public function form(Form $form): Form
{
return $form
->schema([
FileUpload::make('attachment')
->previewable(false)
->storeFiles(false)
->downloadable()
->required()
->acceptedFileTypes(['text/csv']),
Radio::make('type')
->label('Type of Products')
->options([
'1' => 'Products',
'2' => 'Services',
])
->required(),
])
->statePath('data');
}
If I replace these components with say a Text input, it works as expected but the code above, attempts to submit even without data. Now if I copy and paste these into one of my resource forms, the validation works correctly. Not entirely sure what is going on and happy to provide more code etc.
25 replies
FFilament
Created by Damien on 2/6/2024 in #❓┊help
Is there a way to hide a page?
I know you can hide it from the navigation based on authorisation and using this method:
public static function canAccess(): bool
{
return auth()->user()->canManageSettings();
}
public static function canAccess(): bool
{
return auth()->user()->canManageSettings();
}
However I don't want to disable it completely, I just don't want to have the link rendered in the navigation and I cannot find in the docs where this might be a possibility.
4 replies
FFilament
Created by Damien on 2/5/2024 in #❓┊help
Can I change this edit / view behaviour or is it default?
Just following on from my initial question in https://discord.com/channels/883083792112300104/956270111176679516/1204000267918512200 - here is a little clip showing what is currently happening. What I prefer to happen, is that the modal just opens in my current view without first navigating to the resources table view.
70 replies
FFilament
Created by Damien on 2/2/2024 in #❓┊help
How do I correctly create a link to a record from another view?
I has various pages within the app I am building where I am displaying a list of items based on data being passed in. what I haven't been able to find in the docs yet though is how I can correctly link to one of the items being rendered so that it either navigates to the record view or opens up the view modal. Here is some example code with the todo comment being where I would like to action the link from
@foreach($this->data['products'] as $product)
<div class="flex items-center justify-between pt-4">
<div class="space-y-2">
<p class="font-semibold">{{ $product['name'] }}</p>
<p class="flex items-center text-gray-500">
<x-heroicon-s-calendar class="w-5 h-5 mr-1"/>
Updated: {{ date('d-m-Y H:i', strtotime($product['updated_at'] ?? $product['created_at'])) }}
</p>
</div>
<div>
{{-- TODO: Link to view record or view modal --}}
<x-filament::button>
Edit Product
</x-filament::button>
</div>
</div>
@endforeach
@foreach($this->data['products'] as $product)
<div class="flex items-center justify-between pt-4">
<div class="space-y-2">
<p class="font-semibold">{{ $product['name'] }}</p>
<p class="flex items-center text-gray-500">
<x-heroicon-s-calendar class="w-5 h-5 mr-1"/>
Updated: {{ date('d-m-Y H:i', strtotime($product['updated_at'] ?? $product['created_at'])) }}
</p>
</div>
<div>
{{-- TODO: Link to view record or view modal --}}
<x-filament::button>
Edit Product
</x-filament::button>
</div>
</div>
@endforeach
Apologies if this is an easy find, I struggled to do so and I couldn't find a similar thread in the forumn already.
15 replies
FFilament
Created by Damien on 1/25/2024 in #❓┊help
How do I disable the text inputs base on whether or not a checkbox is checked?
No description
5 replies
FFilament
Created by Damien on 1/24/2024 in #❓┊help
Is there a way I can make this Wizard Step layout more fluid?
No description
4 replies
FFilament
Created by Damien on 1/15/2024 in #❓┊help
How do you implement create / edit actions correctly within custom widgets?
Hey everyone! I have been going around in circles a little bit with this and I think I am likely barking up the wrong tree but I have the following class
class RoomsOverview extends Widget implements HasActions, HasForms
{
use InteractsWithActions;
use InteractsWithForms;

protected static string $view = 'filament.resources.quote-resource.widgets.rooms-overview';

protected function getForms(): array
{
return [
'roomForm',
'floorConstructionForm',
];
}

public ?array $data = [];

public function mount(): void
{
$this->roomForm->fill();
$this->floorConstructionForm->fill();
}

public function roomForm(Form $form): Form {...}

public function floorConstructionForm(Form $form): Form {...}

public function createRoomAction(): Action {...}

public function editRoomAction(): Action {...}
}
class RoomsOverview extends Widget implements HasActions, HasForms
{
use InteractsWithActions;
use InteractsWithForms;

protected static string $view = 'filament.resources.quote-resource.widgets.rooms-overview';

protected function getForms(): array
{
return [
'roomForm',
'floorConstructionForm',
];
}

public ?array $data = [];

public function mount(): void
{
$this->roomForm->fill();
$this->floorConstructionForm->fill();
}

public function roomForm(Form $form): Form {...}

public function floorConstructionForm(Form $form): Form {...}

public function createRoomAction(): Action {...}

public function editRoomAction(): Action {...}
}
Creating a room, works as expected, however, I am struggling to get editing a room to work correctly and I feel like I am duplicating code unnecessarily across files. Here are some additional files for context.
// create|edit-room.blade.php
<div class="grid divide-x divide-gray-700 lg:grid-cols-12">
<div class="col-span-8 pr-4">{{ $this->roomForm }}</div>
<div class="col-span-4 pl-4">{{ $this->floorConstructionForm }}</div>
</div>
// create|edit-room.blade.php
<div class="grid divide-x divide-gray-700 lg:grid-cols-12">
<div class="col-span-8 pr-4">{{ $this->roomForm }}</div>
<div class="col-span-4 pl-4">{{ $this->floorConstructionForm }}</div>
</div>
I also have this snippet where I have the edit action on each room in a loop.
<div class="space-y-4 divide-y divide-dashed">
@if($rooms)
@foreach($rooms as $room)
<div class="pt-4 first:pt-0">
<div>
{{ $room->name }}
</div>
<div class="grid gap-5 grid-cols-12">

<div class="col-span-3 flex justify-end">{{ $this->editRoomAction() }}</div>

</div>
</div>
@endforeach
@endif
</div>
<div class="space-y-4 divide-y divide-dashed">
@if($rooms)
@foreach($rooms as $room)
<div class="pt-4 first:pt-0">
<div>
{{ $room->name }}
</div>
<div class="grid gap-5 grid-cols-12">

<div class="col-span-3 flex justify-end">{{ $this->editRoomAction() }}</div>

</div>
</div>
@endforeach
@endif
</div>
39 replies
FFilament
Created by Damien on 1/11/2024 in #❓┊help
makeModalSubmitAction arguments are empty?
I am trying to use the above method to implment a 'save & create another' action however the arguments are always empty even though I am passing it. I took the the example straight from the documentation, code below:
->extraModalFooterActions(fn (Action $action): array => [
// TODO: Get argument to be received by action to identify when modal should be reloaded
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true]),
])
->action(function (array $arguments) {
if ($arguments['another'] ?? false) {
// Reset the form and don't close the modal
dd('another');
}

// ... other form logic
});
->extraModalFooterActions(fn (Action $action): array => [
// TODO: Get argument to be received by action to identify when modal should be reloaded
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true]),
])
->action(function (array $arguments) {
if ($arguments['another'] ?? false) {
// Reset the form and don't close the modal
dd('another');
}

// ... other form logic
});
Not really sure why $arguments is always empty.
7 replies
FFilament
Created by Damien on 1/11/2024 in #❓┊help
How do I correctly use a Filament action on a custom widget?
I have built the following widget as part of a project I am working on (pictured) where by I am listing the rooms associated with a quote. Each room, has an edit room button that I am trying to use as the editAction and when I click on it, something fires in the network tab but there is no visual change in the UI. I will share some code snippets below for additional context. The button to call edit:
// rooms-overview-list.blade.php
...
<x-filament::button size="sm" class="col-start-11 col-span-2"
wire:click="editRoomAction">Edit Room
</x-filament::button>
...
// rooms-overview-list.blade.php
...
<x-filament::button size="sm" class="col-start-11 col-span-2"
wire:click="editRoomAction">Edit Room
</x-filament::button>
...
RoomOverview class where I have defined an edit room action:
// RoomOverview.php
public function editRoomAction(): Action
{
return Action::make('editRoom')
->modalHeading('Edit Room')
->modalContent(fn () => view('filament.resources.quote-resource.modals.edit-room', compact('room')))
->modalFooterActionsAlignment(Alignment::End)
->modalWidth('5xl')
->action(function ($data, $arguments) {
dd($data, $arguments);
});
}
// RoomOverview.php
public function editRoomAction(): Action
{
return Action::make('editRoom')
->modalHeading('Edit Room')
->modalContent(fn () => view('filament.resources.quote-resource.modals.edit-room', compact('room')))
->modalFooterActionsAlignment(Alignment::End)
->modalWidth('5xl')
->action(function ($data, $arguments) {
dd($data, $arguments);
});
}
editRoomAction has been created in a similar way to createRoomAction which is a method I didn't write but works correctly. I have tried passing a $room param as I figured this may be an issue without it but that does not seem to fix the issue either and causes more problems than it fixes. It could be a lack of livewire experience Any help is greatly appreciated.
7 replies
FFilament
Created by Damien on 12/21/2023 in #❓┊help
Extracting form submission data when there are repeaters and relationships
Hey everyone, appreciate it is getting close to Christmas / Holidays for many so I'll try and keep it brief! I am in a scenario where I have stock_products and bom_products and when creating a bom_product, I can select multiple stock_products using a repeater. The data for this is then saved in a bom_stock_products table. On my BomProduct model, I have a method stockProducts() which the repeater uses for the relationship and everything seems to be working fine. What I now need to do, is calculate a cost_price for the bom_product and this is based off of the cost_price for all of the stock_products multiplied by the quantity. The issue I am having is that the $data variable does not contain any information on the stock_products or their id's so that I can query the stock_products table. How would one usually get around this or how can I include the data from the repeater with the relationship to calculate this value.
4 replies
FFilament
Created by Damien on 12/5/2023 in #❓┊help
How to derive a value from another TextInput field correctly.
No description
15 replies
FFilament
Created by Damien on 12/4/2023 in #❓┊help
Repeater fields are missing on view/edit
I have a repeater field that I add multiple values to but when I then view the record or try to edit it, only the first one in shown. Here is the code for my repeater:
$products = Wizard\Step::make('Stock Products')
->schema([
Repeater::make('Stock Products')->schema([
Select::make('stock_product_id')
->options(
StockProduct::class::all()->pluck('name', 'id'),
)
->searchable()
->hiddenLabel(true)
->required(),
])
->relationship('stockProducts')
->itemLabel('Select Stock Product')
->addActionLabel('Add To Group')
->columnSpan(3)
->collapsible(),
]);
$products = Wizard\Step::make('Stock Products')
->schema([
Repeater::make('Stock Products')->schema([
Select::make('stock_product_id')
->options(
StockProduct::class::all()->pluck('name', 'id'),
)
->searchable()
->hiddenLabel(true)
->required(),
])
->relationship('stockProducts')
->itemLabel('Select Stock Product')
->addActionLabel('Add To Group')
->columnSpan(3)
->collapsible(),
]);
This is for a simple resource so I don't know if there is something I should be doing to get all of the values I created the record with? In terms of my database, this Wizard Step is for a group of products and I am looking to add many products. I have a group products table, stock products table and a group stock products table. Not entirely sure what is missing at this point of where I should look in the docs.
38 replies
FFilament
Created by Damien on 11/2/2023 in #❓┊help
Missing form elements for Edit Profile
No description
12 replies
FFilament
Created by Damien on 10/31/2023 in #❓┊help
What is the best way to save data into multiple tables from one form?
Firstly, I did a search within the other help topics and struggled to find anything so apologies if I missed an example! For context, I have 2 tables within my database, projects and project_addresses. When creating a new project, I am using a wizard to capture 3 lots of information project details, admin details and address details the later will be stored in the project_addresses table and separate from the project details and admin details that are stored within the projects table. Also I apologise if this is in the documentation, the only thing I found which seemed somewhat related was https://filamentphp.com/docs/3.x/forms/advanced#saving-data-to-relationships but this moves on to talking about loading data which threw me off.
35 replies