Wim
Fileupload to AWS S3
I'm trying to store images on AWS S3. The moment I upload an image it creates a folder
livewire-tmp
(with the image inside) in the bucket in AWS S3 in it. So far so good....However, the moment I press the create button in Filament, it writes it to local disk (and livewire-tmp folder is gone at AWS S3). Despite the below configuration. Am I overlooking something?
.env file
FILESYSTEM_DISK=s3
AWS_ACCESS_KEY_ID=A***A
AWS_SECRET_ACCESS_KEY=f***
AWS_DEFAULT_REGION=eu-central-1
AWS_BUCKET=my-bucket-dev
AWS_URL="https://my-bucket-dev.s3.amazonaws.com/"
AWS_USE_PATH_STYLE_ENDPOINT=true
config/filesystem.php:
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
],
Filament resource
FileUpload::make('photo_featured')
->disk('s3')
->acceptedFileTypes($types = ['jpg', 'jpeg', 'png'])
->image()
->maxSize(15000)
->imageEditor()
->columnSpan('full'),
5 replies
Conditionally showing TextInput or changing default
I want to show a different default value in the TextInput depending on the organization_type. I have therefore created two TextInput fields. I hide the TextInput depending on the type of organization.
As such this works, but I also need the default value to be different depending on the organization type. While the TextInput is correctly chosen (e.g I can see that on the label), the default value of the first TextInput is always shown.
So concrete: I have two types of organizations (e.g. an individual and a company). When organization type is individual, I want to show a textInput with the name of the individual. When organization type is company, I want to show a textInput with default value of the user name, with "'s Company" added to the default value
Select::make('organization_type')
->live()
->options(OrganizationType::class)
->required()
->afterStateUpdated(function ($state, Set $set) {
$set('organization_type', $state);
}),
TextInput::make('name')
->label('Organization Name')
->default( Filament::getUsername(auth()->user()) . " 's Company")
->visible(fn (Get $get): bool =>
$get('organization_type') === 'company'
),
TextInput::make('name')
->label('Individual Name')
->default( Filament::getUsername(auth()->user()) )
->visible(fn (Get $get): bool =>
$get('organization_type') === 'individual'
),
3 replies
Placeholder color in TextColumn
I have the following:
Tables\Columns\TextColumn::make('receiver.name')
->label('To')
->placeholder(auth()->user()->name),
The default style is to grey out the placeholder. Is there a way to set the placeholder in another color? Or conditionally color it (e,.g I want it to be red if the value of receiver.name equals the auth()->user()->name() )3 replies
Multi-tenant: search across all products
I have a multitenant application. My tenant is called 'organization'. I want a user to be able to ask information about a product by sending a message. I have therefore a MessageResource with below snippet. The idea is that a user can search across all products in the database, not only the products that he's owning (=assigned to his organization).
Below code works but only shows the products linked to the organization.
Select::make('product_id')
->label('Product')
->columnSpan(1)
->searchable()
->getSearchResultsUsing(function ($search) {
if (strlen($search) < 3) {
return [];
}
return Product::where('name', 'like', "%{$search}%")
->limit(50)
->get()
->pluck('name', 'id');
})
->getOptionLabelUsing(fn ($value): ?string => Product::find($value)?->name)
->disabled(false),
I also have the following:
protected static function booted(): void
{
static::addGlobalScope('organization', function (Builder $query) {
if (auth()->hasUser()) {
$query->where('organization_id', auth()->user()->organization_id);
}
});
}
This explains of course why I only see the products for the organization.
I read that Filament does scoping to tenant automatically, so the above global scope seems redundant. Still I wanted to have it to have a secure feeling.
Two quesions:
1) can I safely remove the global scope?
2) Is there a way I could still enforce a scope, except for this one resource (MessageResource)?
Any suggestions?11 replies
Update a field based on select value
I have a field called 'Country' where a user can select a value. When a user selects a country, it gets stored in the database.
Select::make('country')
->required()
->native(false)
->options(Country::class)
->dehydrated(false),
I want to write a two letter country code to another field in the database (e.g country_iso) each time the user selects a value in the above select box. So if a user selects 'Netherlands' I want to write 'Netherlands' to the 'country' field, but also 'NL' in the billing_country.
As a test, in the below snippet, I tried to update the Text Input to display the selected option but that does not work.
Select::make('country')
->required()
->native(false)
->options(Country::class)
->dehydrated(false)
->afterStateUpdated(function (Set $set, ?string $state) {
$set('country', $state);
$set('billing_country_placeholder', $state ? "Selected country: $state" : 'No country selected');
}),
TextInput::make('billing_country')
->live()
->placeholder(fn (Get $get): string => $get('billing_country_placeholder') ?? 'No country selected')
4 replies
Open Edit modal from Action Group
I have a Filament table in my resource. When I click on a row, a View modal opens. This is because of the recordUrl and recordAction in below snippet.
When I click on an 'edit' action in the action group, it opens the edit page but I also want it to open as an (edit) modal. How can I do this?
->actions([
ActionGroup::make([
Tables\Actions\EditAction::make(),
Tables\Actions\ViewAction::make() ,
])
->button()
->icon('heroicon-m-ellipsis-horizontal')
])
->recordUrl(null)
->recordAction(Tables\Actions\ViewAction::class);
Note: when I change the (Tables\Actions\ViewAction::class);
to (Tables\Actions\EditAction::class);
it opens indeed the edit modal. But I don't want it to open when clicking a row, I want it to open when the Edit is clicked in the ActionGroup.4 replies
Redirect to app panel instead of admin panel
I have an admin panel and an app panel. The default() is added on the admin panel.
Each time I try to login a user (after invitation email) using auth()->login($user); it would redirect to the admin panel.
Is there a way I can 'force' to go to the app panel?
6 replies
Translating mails
Sending password reset, emailverification mails works nicely but I would like to send the mails in a different language. I have translated the rest of the app in different languages and this works. But despite setting the APP_LOCALE=nl, the mails are sent in English.
Any suggestions?
1 replies
Don't show Actions for Database notifications that are marked as read
I have the following database notification:
This successfully shows a button on each notification. How can I NOT show the button when the notification is read (e.g. in the notifications table there is a read_at that is not null in such case)
I tried it as follows but that does not work:
Any idea's?
3 replies
Favorite products: many to many not working
I have an app where users can favor many products. This is done via a many to many relation with a Favorite pivot table. Adding things into the database works.
The
favorites
table is as follows:
In Filament I have a Favorites resources where the idea is the user can get an overview of the products he's favoured. In a Filament table I have the following:
The username is printed but the product name is not. Any idea how to do this? I keep on struggling with this.
Some more information in case relevant:
User Model:
Product model:
Favorite model:
4 replies
Spark's current subscription plan in Filament Form
I'm integrating Laravel Spark with Filament. I would like to show the user's current subscription in a Form (on the Profile page)
I can get the subscription as follows:
Obviously this does not work. Any idea how I can show the current user's subscription
For info, here's the relevant database section:
1 replies
Filament with Spark integration
I'm currently integrating Filament v3 with Laravel Spark for a multi-tenant application.
In the AppPanelProvider.php I have added
->requiresTenantSubscription()
, the document states that users will be redirected to the billing page if they don't have an active subscription.
My issue is that I'm always being redirected to the billing portal. I do have a subscription for the organization (which is the tenant). I get a 'Your subscription has been started successfully.', as well as a way to 'change the subscription plan' as well as entries in the database subscription table.
The expected behaviour would be that in this case (with a subscription) it would simply allow me to go the the Filament backend of my application.
Any ideas?3 replies
Multi-tenancy: don't show tenancy menu when individual user
I have setup multi-tenancy according to the information here.
I know I can use tenantMenu(false) as I did below.
However, I want to do this only when a user is an individual. In my database I have a table organizations that has a column
is_individual
. How can I change is to that only organizations see the menu whereas individual users don't get to see it.
Or would I need two panels: one for individuals and one for organizations?2 replies