Darpan
Darpan
FFilament
Created by Darpan on 9/7/2023 in #❓┊help
How to use SpatieMediaLibraryFileUpload in hintAction?
I Have a hint action to create new record like:
->hintAction(
Action::make('create_amenity')
->form([
TextInput::make('name'),
SpatieMediaLibraryFileUpload::make('image'),
])
->action(function ($data) {
dd($data);
// create amenity
}),
),
->hintAction(
Action::make('create_amenity')
->form([
TextInput::make('name'),
SpatieMediaLibraryFileUpload::make('image'),
])
->action(function ($data) {
dd($data);
// create amenity
}),
),
but I only get name in $data array, how can I access image?
13 replies
FFilament
Created by Darpan on 9/1/2023 in #❓┊help
How to use nested relationship in SelectFilter?
I have State, City and Suburb models. Suburb belongs to City, City belongs to State. In table TextColumn::make('city.state.name') is working fine. But in table select filter I am getting following error. SelectFilter::make('state')->relationship('city.state', 'name') Call to undefined method App\Models\Suburb::city.state()
7 replies
FFilament
Created by Darpan on 8/18/2023 in #❓┊help
Panel domain - CORS Issue - Spatie Media Library File Upload
When I use $panel->domain('admin.example.test') I get following error Access to fetch at 'https://example.test/storage/1/mWYF1pIRZoK9jwFPajd7FCdDN2kdua-metaYXV0aG9yLWJhbm5lci5qcGc=-.jpg' from origin 'https://admin.example.test' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. but it works when I remove ->domain() and use ->path(). How can I make it work?
11 replies
FFilament
Created by Darpan on 8/4/2023 in #❓┊help
User menu items, route not found
I added user menu item as per the docs (https://filamentphp.com/docs/3.x/panels/navigation#customizing-the-user-menu), but getting route not found error. When I run php artisan route:list, I can see that the route is registered.
->userMenuItems([
MenuItem::make()
->label('Profile')
->url(route(EditProfile::getRouteName('admin'))),
//->url(route('filament.admin.pages.edit-profile')),
])
->userMenuItems([
MenuItem::make()
->label('Profile')
->url(route(EditProfile::getRouteName('admin'))),
//->url(route('filament.admin.pages.edit-profile')),
])
5 replies
FFilament
Created by Darpan on 8/2/2023 in #❓┊help
Search field losing focus
When I type something in the search box of the table, it loses focus after showing the search results. For example, let's say I want to search for "mango." When I type "man" and wait for a second, it fetches results containing "man," but the search box loses focus, and I can't finish typing the word. Is this supposed to happen? I also have another project in filament v2 in production, and when I checked this behaviour there, the search box didn't lose focus.
5 replies
FFilament
Created by Darpan on 6/29/2023 in #❓┊help
Select component resets after save or state update
I have a simple form on custom page with select component but when I click on save button the it resets the select component (blank with no styling) and I get an error in console: Uncaught (in promise) TypeError: Expected one of the following types text|select-one|select-multiple Test.php
public User $user;

protected function getFormSchema(): array
{
return [
Card::make([
Select::make('business_model')
->options([...])
->searchable(),

Select::make('property_types')
->options([...])
->multiple()
->reactive()
])->columns()
];
}

protected function getFormModel(): Model|string|null
{
return $this->user;
}

public function save(): void
{
$this->user->update($this->form->getState());
$this->notify('success', 'Saved');
}

public function mount(): void
{
$this->user = Auth::user();
$this->form->fill($this->user->toArray());
}
}
public User $user;

protected function getFormSchema(): array
{
return [
Card::make([
Select::make('business_model')
->options([...])
->searchable(),

Select::make('property_types')
->options([...])
->multiple()
->reactive()
])->columns()
];
}

protected function getFormModel(): Model|string|null
{
return $this->user;
}

public function save(): void
{
$this->user->update($this->form->getState());
$this->notify('success', 'Saved');
}

public function mount(): void
{
$this->user = Auth::user();
$this->form->fill($this->user->toArray());
}
}
test.blade.php
<x-filament::page>
<form wire:submit.prevent="save" class="space-y-6">
{{ $this->form }}

<x-filament::button type="submit" wire:target="save">Save changes</x-filament::button>
</form>
</x-filament::page>
<x-filament::page>
<form wire:submit.prevent="save" class="space-y-6">
{{ $this->form }}

<x-filament::button type="submit" wire:target="save">Save changes</x-filament::button>
</form>
</x-filament::page>
4 replies
FFilament
Created by Darpan on 6/28/2023 in #❓┊help
Unable to hide default widgets
Default widgets are visible even after removing them from filament.php config file. tried clearing cache, views, filament:upgrade etc.
6 replies
FFilament
Created by Darpan on 4/18/2023 in #❓┊help
Custom brand logo not showing on live server and Translation also not working?
I followed this, https://filamentphp.com/docs/2.x/admin/appearance#changing-the-brand-logo, its working on local machine, but not working on live server, it fallback to text version.
3 replies
FFilament
Created by Darpan on 4/13/2023 in #❓┊help
Scroll to top on pagination select after next page data is received
The following code works, but on the live server it scrolls to top way before loading next page data, is there any way to wait for next page data and then scroll?
Filament::registerRenderHook('scripts.end',
fn(): string => new HtmlString('
<script>
document.addEventListener("click", function(e) {
if (e?.target?.closest("nav")?.classList.contains("filament-tables-pagination")){
window.scrollTo({top: 0, behavior: "smooth"});
}
});
</script>
'),
);
Filament::registerRenderHook('scripts.end',
fn(): string => new HtmlString('
<script>
document.addEventListener("click", function(e) {
if (e?.target?.closest("nav")?.classList.contains("filament-tables-pagination")){
window.scrollTo({top: 0, behavior: "smooth"});
}
});
</script>
'),
);
1 replies
FFilament
Created by Darpan on 4/13/2023 in #❓┊help
Livewire.js 404 when app is hosted in sub directory
My application is in "app" sub directory https://example.com/app, filament admin is showing login page but livewire.js is not found. Console shows https://example.com/livewire/livewire.js not found. How can I make it work? All other assets like filament.css, app.css, app.js loading without any issues.
11 replies
FFilament
Created by Darpan on 4/10/2023 in #❓┊help
How to prevent already selected value in repeater?
I am using repeater to add working hours and I don't want users to select same day twice. How can I prevent this?
13 replies
FFilament
Created by Darpan on 4/10/2023 in #❓┊help
$record is null inside hidden()
$table->columns([
TextColumn::make('url')
->url(fn($record) => $record->url) // working
->hidden(fn($record) => $record->url), // null
]),
$table->columns([
TextColumn::make('url')
->url(fn($record) => $record->url) // working
->hidden(fn($record) => $record->url), // null
]),
Is this expected behavior? Or I am doing something wrong?
3 replies
FFilament
Created by Darpan on 4/10/2023 in #❓┊help
Remember section collapse position
Is it possible to remember if section(https://filamentphp.com/docs/2.x/forms/layout#section) is collapsed or open after reload?
2 replies
FFilament
Created by Darpan on 4/8/2023 in #❓┊help
Split and Stack table layout issue.
13 replies
FFilament
Created by Darpan on 4/7/2023 in #❓┊help
FileUpload - Manipulate image before saving.
I am using Intervention library to mainuplate images like resizing, encoding to png, how can I use this with FileUpload?
Image::make($img)->encode('png')->resize(16, 16)->save($path);
Image::make($img)->encode('png')->resize(16, 16)->save($path);
FileUpload::make('img')
FileUpload::make('img')
2 replies
FFilament
Created by Darpan on 3/18/2023 in #❓┊help
Toggle column issue.
Toggling one record changes other records.
Tables\Columns\ToggleColumn::make('published')
->label('Publish')
->onColor('success')
->alignCenter()
->tooltip(fn(News $record) => $record->published
? 'Unpublish' : 'Publish'),
Tables\Columns\ToggleColumn::make('published')
->label('Publish')
->onColor('success')
->alignCenter()
->tooltip(fn(News $record) => $record->published
? 'Unpublish' : 'Publish'),
8 replies
FFilament
Created by Darpan on 3/14/2023 in #❓┊help
ToggleColumn Action
I have a ToggleColumn on my table that updates the pinned status of news posts. However, I want to limit the number of pinned posts to three, so I have disabled the toggle when the post count is equal to or greater than three. To ensure that the toggle behaves as intended, I am using the ->action() function. However, it does not seem to be working correctly. I need to investigate this further. Another issue I have noticed is that when I update the toggle status of a post, the other records in the table do not update (i.e., disable) automatically. Instead, I need to manually refresh the page. I would like to understand why this is happening and find a solution to make the updates happen automatically.
Tables\Columns\ToggleColumn::make('pinned')
->tooltip(fn(News $record): string => $record->pinned ? 'Unpin' : 'Pin')
->action(function (News $record) {

// This does not work...

if(News::wherePinned(true)->count >= 3) {
Notification::make('Error')
->body('You can pin only 3 news.')
->danger()
->send();
} else {
$record->update(['pinned' => true]);
}
})
->disabled(fn(News $record) => $record->pinned == false && News::wherePinned(true)->count() >= 3),
Tables\Columns\ToggleColumn::make('pinned')
->tooltip(fn(News $record): string => $record->pinned ? 'Unpin' : 'Pin')
->action(function (News $record) {

// This does not work...

if(News::wherePinned(true)->count >= 3) {
Notification::make('Error')
->body('You can pin only 3 news.')
->danger()
->send();
} else {
$record->update(['pinned' => true]);
}
})
->disabled(fn(News $record) => $record->pinned == false && News::wherePinned(true)->count() >= 3),
6 replies
FFilament
Created by Darpan on 3/9/2023 in #❓┊help
How to set existing image to file upload field?
I am trying to fetch favicon from url and update file upload field with fetched icon but preview is not working.
TextInput::make('url')->lazy()
->afterStateUpdated(function (Closure $set, $state) {
$domain = UrlHelper::getDomain($state);
$faviconName = str($domain)->replace('.', '-');
$faviconPath = public_path('images/favicons/' . $faviconName . '.png');
try {
$ic = Image::make('https://api.faviconkit.com/' . $domain . '/16')
->encode('png')
->resize(16, 16)
->save($faviconPath);
$ic->destroy();
} catch (Exception) {
copy(public_path('images/default-favicon.png'), $faviconPath);
}

// How to do this?
$set('favicon', [$faviconPath]);
}),

FileUpload::make('favicon')->image(),
TextInput::make('url')->lazy()
->afterStateUpdated(function (Closure $set, $state) {
$domain = UrlHelper::getDomain($state);
$faviconName = str($domain)->replace('.', '-');
$faviconPath = public_path('images/favicons/' . $faviconName . '.png');
try {
$ic = Image::make('https://api.faviconkit.com/' . $domain . '/16')
->encode('png')
->resize(16, 16)
->save($faviconPath);
$ic->destroy();
} catch (Exception) {
copy(public_path('images/default-favicon.png'), $faviconPath);
}

// How to do this?
$set('favicon', [$faviconPath]);
}),

FileUpload::make('favicon')->image(),
When I dump data I can see 'favicon' field with correct image path but preview is not working on file upload component.
4 replies
FFilament
Created by Darpan on 3/8/2023 in #❓┊help
TextInput with visibleOn() and visible()
I want to show published date on edit page only and only if the published date is not null, I am doing like following but I am getting error on create page.
App\Filament\Resources\{closure}(): Argument #1 ($record) must be of type App\Models\ModelName, null given
App\Filament\Resources\{closure}(): Argument #1 ($record) must be of type App\Models\ModelName, null given
TextInput::make('published_at')
->disabled()
->formatStateUsing(fn($record) => $record?->published_at?->format('M d, Y - h:i:s A'))
->visibleOn('edit')
->visible(fn(ModelName $record): bool => (bool)$record->published_at),
TextInput::make('published_at')
->disabled()
->formatStateUsing(fn($record) => $record?->published_at?->format('M d, Y - h:i:s A'))
->visibleOn('edit')
->visible(fn(ModelName $record): bool => (bool)$record->published_at),
5 replies