Mansoor Khan
Mansoor Khan
FFilament
Created by Mansoor Khan on 5/7/2024 in #❓┊help
Open a Modal when field state changes
Is it possible to open a modal when the field state changes. I need to add something like this to the Toggle field using a Macro.
Toggle::make('is_published')
->requiresConfirmation(),
Toggle::make('is_published')
->requiresConfirmation(),
Has anyone tried something, any trick? We could dispatch the open-modal event but then we also need to register it somewhere and should be able to cancel/proceed the toggle state.
Toggle::make('is_published')
->live()
->afterStateUpdated(function (Component $livewire) {
$livewire->dispatch('open-modal', 'modal-id');
}),
Toggle::make('is_published')
->live()
->afterStateUpdated(function (Component $livewire) {
$livewire->dispatch('open-modal', 'modal-id');
}),
7 replies
FFilament
Created by Mansoor Khan on 4/17/2024 in #❓┊help
Use FilterAction in a custom widget
Hi, I am trying to use FilterAction in a custom widget. It appears beside other action button but does not open the filter drop-down. Is it possible to use FilterAction just like other actions? Am i missing something?
class CustomStatWidget extends Widget implements HasActions, HasForms
{
use HasFiltersAction;
use HasFiltersForm;
use InteractsWithActions;
use InteractsWithForms;
use InteractsWithPageFilters;

public function applyFiltersAction(): FilterAction
{
return FilterAction::make()
->label('')
->icon('heroicon-o-funnel')
->color('gray')
->iconButton()
->form([
DatePicker::make('startDate'),
DatePicker::make('endDate'),
// ...
])
->action(function () {

});
}
}
class CustomStatWidget extends Widget implements HasActions, HasForms
{
use HasFiltersAction;
use HasFiltersForm;
use InteractsWithActions;
use InteractsWithForms;
use InteractsWithPageFilters;

public function applyFiltersAction(): FilterAction
{
return FilterAction::make()
->label('')
->icon('heroicon-o-funnel')
->color('gray')
->iconButton()
->form([
DatePicker::make('startDate'),
DatePicker::make('endDate'),
// ...
])
->action(function () {

});
}
}
<div class="flex items-center gap-2">
{{ $this->createResourceAction }}
{{ $this->viewResourceAction }}
{{ $this->applyFiltersAction }}
</div>
<div class="flex items-center gap-2">
{{ $this->createResourceAction }}
{{ $this->viewResourceAction }}
{{ $this->applyFiltersAction }}
</div>
4 replies
FFilament
Created by Mansoor Khan on 3/21/2024 in #❓┊help
Possible Bug in Action ->disabled() and ->hidden()
I have added Filament action to a custom livewire page. The disabled function works a little odd, the condition changes to true/false but the ->action() would not execute. If i remove the disabled(), it works as expected. Can any one reproduce this?
public function nextPageAction(): Action
{
return Action::make('nextPage')
->button()
->disabled(fn () => $this->totalPages <= 1 || $this->page === $this->totalPages)
// ->hidden($this->totalPages <= 1 || $this->page === $this->totalPages)
->action(function () {
dd($this->page);
$this->nextPage();
});
}
public function nextPageAction(): Action
{
return Action::make('nextPage')
->button()
->disabled(fn () => $this->totalPages <= 1 || $this->page === $this->totalPages)
// ->hidden($this->totalPages <= 1 || $this->page === $this->totalPages)
->action(function () {
dd($this->page);
$this->nextPage();
});
}
3 replies
FFilament
Created by Mansoor Khan on 3/16/2024 in #❓┊help
How to get Field component data/config in Form Action
Can we get the field component data or the configurations in the mounted form action?
Forms\Components\FileUpload::make('image')
->disk('public')
->directory('posts/featured-images')
->hintAction(
Action::make('custom_action')
->action(function () {
// get the disk and directory from the field
})
),
Forms\Components\FileUpload::make('image')
->disk('public')
->directory('posts/featured-images')
->hintAction(
Action::make('custom_action')
->action(function () {
// get the disk and directory from the field
})
),
4 replies
FFilament
Created by Mansoor Khan on 3/13/2024 in #❓┊help
Upload image from URL
I am trying to upload a file from url to FileUpload field. Has anyone tried something like this before? I am able to upload the file locally, then save the path to db and then reset the FileUpload field state with new path. But I dont want to save it DB after downlaoding the file from url. I just want to pass it to FileUpload field, so that user can see a preview. Here is what i am trying. Everything works, file also saves correctly on submit and also previews after submit. But it does not preview unless you submit it. so wondering if there is a way to tell Filament to preview it.
Forms\Components\FileUpload::make('featured_image')->hintAction(
Filament\Forms\Components\Actions\Action::make('url_uploader')
->form([TextInput::make('url')->label('Image URL')])
->action(function (Set $set, Component $livewire, array $data) {
$filePath = UrlUploadedFile::createFromUrl($data['url'])
->store('livewire-tmp', ['disk' => 'local']);
$filePath = explode('/', $filePath)[1];

$file = TemporaryUploadedFile::createFromLivewire($filePath);

$set($livewire->mountedFormComponentActionsComponents[0], [$file], true);
}),
)
Forms\Components\FileUpload::make('featured_image')->hintAction(
Filament\Forms\Components\Actions\Action::make('url_uploader')
->form([TextInput::make('url')->label('Image URL')])
->action(function (Set $set, Component $livewire, array $data) {
$filePath = UrlUploadedFile::createFromUrl($data['url'])
->store('livewire-tmp', ['disk' => 'local']);
$filePath = explode('/', $filePath)[1];

$file = TemporaryUploadedFile::createFromLivewire($filePath);

$set($livewire->mountedFormComponentActionsComponents[0], [$file], true);
}),
)
42 replies
FFilament
Created by Mansoor Khan on 3/7/2024 in #❓┊help
Get resource in Action class
I am creating a plugin and it provides a page just EditRecords page. Users can extend this page and specify the $resource. Now I am creating two Actions, one Table action and another normal Page action to redirect to users to the Custom page that extends the plugin Page. This action can be used on Edit record pages. The problem is i cannot get the $resource, to redirect them to correct resource page.
4 replies
FFilament
Created by Mansoor Khan on 2/15/2024 in #❓┊help
Reorder on Select field relationship
No description
2 replies
FFilament
Created by Mansoor Khan on 12/2/2023 in #❓┊help
How to Create an Action class that can be used on both Table and Form
Hi, I have a pretty big action with form and form handling logic. I need to extract it to a class which can be used on both the Resource Table and the Resource Edit form.
3 replies
FFilament
Created by Mansoor Khan on 11/28/2023 in #❓┊help
Disabled not working on RichEditor
I am using latest version of Filament and the disabled is not working on RichEditor field
4 replies
FFilament
Created by Mansoor Khan on 10/3/2023 in #❓┊help
How to use Spatie Media Library in a json repeater field.
I have a requirement, where I need to use Spatie Media file upload and store the model_id in json column. Here is the required structure:
{
"items": [
{"key": "Key 1", "value": "value 1", "model_id": 1},
{"key": "Key 2", "value": "value 2", "model_id": 2},
]
}
{
"items": [
{"key": "Key 1", "value": "value 1", "model_id": 1},
{"key": "Key 2", "value": "value 2", "model_id": 2},
]
}
Here is what i am trying, It can read files from Media model. I am trying to find a way to set component when save form. When i dd() the form data, the items array contains only key/value properties but not the model_id
protected function mutateFormDataBeforeSave(array $data): array
{
dd($data);

return $data;
}
protected function mutateFormDataBeforeSave(array $data): array
{
dd($data);

return $data;
}
6 replies
FFilament
Created by Mansoor Khan on 9/28/2023 in #❓┊help
Is it possible to use FileUpload field without using Form build or Form component?
I am working on a project where i need build the Filepond livewire component. I am curios if its possible to use just the fileupload field without using the Form builder.
7 replies
FFilament
Created by Mansoor Khan on 9/21/2023 in #❓┊help
Not able to use Filament notifications on front site
No description
4 replies
FFilament
Created by Mansoor Khan on 8/29/2023 in #❓┊help
Table builder ->wrap() is not working after v3.0.30
With the new versions of Filament the wrap() method on Table builder does not work. I have downgraded from v3.0.36 to v3.0.30 as a fix for now.
2 replies
FFilament
Created by Mansoor Khan on 8/25/2023 in #❓┊help
Filamentv3 form.css conflicts with Spatie Livewire comments editor
No description
6 replies
FFilament
Created by Mansoor Khan on 8/24/2023 in #❓┊help
Not able to user Spatie Livewire Comments with Filament v3
I am trying to load Livewire Comments styles and scripts but i get a warning the scripts are loaded before Alpine.
public function boot(): void
{
FilamentView::registerRenderHook(
'panels::head.end',
fn (): string => Blade::render('<x-comments::styles />'),
);

FilamentView::registerRenderHook(
'panels::head.end',
fn (): string => Blade::render('<x-comments::scripts />'),
);
}
public function boot(): void
{
FilamentView::registerRenderHook(
'panels::head.end',
fn (): string => Blade::render('<x-comments::styles />'),
);

FilamentView::registerRenderHook(
'panels::head.end',
fn (): string => Blade::render('<x-comments::scripts />'),
);
}
6 replies
FFilament
Created by Mansoor Khan on 8/17/2023 in #❓┊help
How to add two Create Form Actions
I have a resource and inside create page I am defining create form action in header actions. But the action does not work for some reason, however the default form action works as expected. following action does not work:
class CreateCategory extends CreateRecord
{
protected static string $resource = CategoryResource::class;

protected function getHeaderActions(): array
{
return [
$this->getCreateFormAction(),
];
}
}
class CreateCategory extends CreateRecord
{
protected static string $resource = CategoryResource::class;

protected function getHeaderActions(): array
{
return [
$this->getCreateFormAction(),
];
}
}
Am i missing something or doing something wrong here?
10 replies
FFilament
Created by Mansoor Khan on 8/3/2023 in #❓┊help
What is the replacement for Filament::pushMeta
I am using v3 and i need use pushMeta but i dont know what is the replacment of it in v3
9 replies
FFilament
Created by Mansoor Khan on 7/30/2023 in #❓┊help
[plugins-dev] How to get resource column in Filamentv3
I am trying to upgrade a plugin to support v3. In v2 we were able to get table column from specified resource using:
use Filament\Resources\Table;

$columns = $this->resource::table(Table::make())
->getColumns();
use Filament\Resources\Table;

$columns = $this->resource::table(Table::make())
->getColumns();
When I try following in Filament v3 i get an error:
use Filament\Tables\Table;

// I am passing $this here because in v3 make requires HasTable $livewire param.
$columns = $this->resource::table(Table::make($this))
->getColumns();
use Filament\Tables\Table;

// I am passing $this here because in v3 make requires HasTable $livewire param.
$columns = $this->resource::table(Table::make($this))
->getColumns();
Error: Property [$isCachingForms] not found on component
4 replies
FFilament
Created by Mansoor Khan on 5/15/2023 in #❓┊help
Make sidebar closed by default on mobile.
When you login inside Admin panel on mobile for first time, you get the sidebar opened by default. How can i disable that? Ofcourse it would be opened again if i closed and never left opened. But i want to keep it closed for when a user logs in for first time. Thanks.
13 replies
FFilament
Created by Mansoor Khan on 4/26/2023 in #❓┊help
Upload Image/File from URL
Hello. I have an action on Edit Resource where i randomly download an image from web and upload it to the field but its not working.. what i am doing wrong. Here is what i am trying..
filePath = UrlUploadedFile::createFromUrl($imageLink)->store('posts/featured_images');
// $file = UrlUploadedFile::createFromUrl($imageLink);

// $this->record->featured_image = $filePath;
// $this->record->featured_image = $file;
$this->record->featured_image = TemporaryUploadedFile::createFromLivewire($filePath);
$this->record->save();

$this->refreshFormData([
'featured_image',
]);

class UrlUploadedFile extends UploadedFile
{
public static function createFromUrl(string $url, string $originalName = '', string $mimeType = null, int $error = null, bool $test = false): self
{
if (! $stream = @fopen($url, 'r')) {
throw new Exception('Can\'t open file from url ' . $url . '.');
}

$tempFile = tempnam(sys_get_temp_dir(), 'url-file-');

file_put_contents($tempFile, $stream);

return new static($tempFile, $originalName, $mimeType, $error, $test);
}
}
filePath = UrlUploadedFile::createFromUrl($imageLink)->store('posts/featured_images');
// $file = UrlUploadedFile::createFromUrl($imageLink);

// $this->record->featured_image = $filePath;
// $this->record->featured_image = $file;
$this->record->featured_image = TemporaryUploadedFile::createFromLivewire($filePath);
$this->record->save();

$this->refreshFormData([
'featured_image',
]);

class UrlUploadedFile extends UploadedFile
{
public static function createFromUrl(string $url, string $originalName = '', string $mimeType = null, int $error = null, bool $test = false): self
{
if (! $stream = @fopen($url, 'r')) {
throw new Exception('Can\'t open file from url ' . $url . '.');
}

$tempFile = tempnam(sys_get_temp_dir(), 'url-file-');

file_put_contents($tempFile, $stream);

return new static($tempFile, $originalName, $mimeType, $error, $test);
}
}
13 replies