Vincent
Vincent
FFilament
Created by Vincent on 10/11/2023 in #❓┊help
Removing tenant parameter and middleware for SimplePage
Hi! In the app I'm building, users can belong to multiple tenants. I'm tracking their current organization via a currentOrganization relationship on the User model. If a user's current org is empty, I'd like to redirect them to a page, /current-organization, where they can select which of their organizations they'd like to administer. I'm doing this via middleware:
// EnsureUserHasCurrentOrganization middleware
if (
! $user->current_organization_id
&& $user->organizations()->exists()
) {
return redirect(
'/current-organization',
Response::HTTP_FOUND
);
}
// EnsureUserHasCurrentOrganization middleware
if (
! $user->current_organization_id
&& $user->organizations()->exists()
) {
return redirect(
'/current-organization',
Response::HTTP_FOUND
);
}
and /current-organization:
class CurrentOrganization extends SimplePage
{
use HasRoutes;

protected static string $view = 'filament.pages.current-organization';

public static function routes(Panel $panel): void
{
$slug = static::getSlug();

Route::get("/{$slug}", static::class)
->middleware(static::getRouteMiddleware($panel))
->withoutMiddleware(static::getWithoutRouteMiddleware($panel))
->name('current-organization');
}

public static function getWithoutRouteMiddleware(Panel $panel): string|array
{
return [
...Arr::wrap(static::$withoutRouteMiddleware),
EnsureUserHasCurrentOrganization::class,
];
}
}
class CurrentOrganization extends SimplePage
{
use HasRoutes;

protected static string $view = 'filament.pages.current-organization';

public static function routes(Panel $panel): void
{
$slug = static::getSlug();

Route::get("/{$slug}", static::class)
->middleware(static::getRouteMiddleware($panel))
->withoutMiddleware(static::getWithoutRouteMiddleware($panel))
->name('current-organization');
}

public static function getWithoutRouteMiddleware(Panel $panel): string|array
{
return [
...Arr::wrap(static::$withoutRouteMiddleware),
EnsureUserHasCurrentOrganization::class,
];
}
}
This page is registered via the pages method in the Panel Provider. There are two problems: 1. The route above still appears in the {tenant} namespace. php artisan routes:list | grep current shows: GET|HEAD myurl.test/{tenant}/current-organization ... filament.admin.pages.current-organization › App\Filament\Pages\CurrentOrganization 2. It gets stuck in a redirect loop despite explicitly disabling the offending middleware. Is this a bug, or am I missing something? How can I remove it from the tenant routes? And how can I disable the middleware?
4 replies
FFilament
Created by Vincent on 9/19/2023 in #❓┊help
Is there a good way to compose fields together in a Custom Field?
Here's what I'm trying to do: A custom field comprised of a Text Input and a Radio Input. You type a search into the text input, an API is called on the backend, and the results of the API call populate the Radio. I'd like those two inputs to be wrapped up inside a Custom Field so that I can use the default Text and Radio input style and functionality, but also add some simple custom HTML in the Blade component. Does this approach make sense, or would it be better to just copy/paste from default Filament components? Below is the (broken) code as it stands. The afterStateUpdated callback is never called, but I don't quite understand why -- I think the container call is changing the scope of the TextInput? But without setting container, I get an exception.
16 replies
FFilament
Created by Vincent on 8/29/2023 in #❓┊help
TextColumn placeholder empty
Hi! I've got an app I just upgraded from v2 to v3. I've got most of the kinks worked out, but one small thing is bugging me: ->placeholder seems to not do much. Here's the column:
TextColumn::make('cost_usd')
->placeholder('In progress')
->label('Cost')
->formatStateUsing(
fn (float $state): string => '$' . number_format($state, 2)
),
TextColumn::make('cost_usd')
->placeholder('In progress')
->label('Cost')
->formatStateUsing(
fn (float $state): string => '$' . number_format($state, 2)
),
The cost_usd attribute is a nullable float (😬). formatStateUsing here works fine, and the column in the resulting table looks correct...except if the value is null. placeholder doesn't seem to make a difference. The table is in a custom widget and otherwise works great. Am I missing something?
15 replies