Gaurav
Gaurav
FFilament
Created by Gaurav on 6/13/2024 in #❓┊help
Get full path of FileUpload
I've defined a file upload field for uploading PDF to a model, as:
Forms\Components\FileUpload::make('pdf')
->acceptedFileTypes(['application/pdf'])
->visibleOn('create'),
Forms\Components\FileUpload::make('pdf')
->acceptedFileTypes(['application/pdf'])
->visibleOn('create'),
Now, I want to access this file after the model is created using model::boot method as below:
public static function boot()
{
parent::boot();
static::created(function ($model) {
$pdf = new Pdf($model->pdf);
//...
}
}
public static function boot()
{
parent::boot();
static::created(function ($model) {
$pdf = new Pdf($model->pdf);
//...
}
}
However, I get error as: File '01J085D4C9VX4Q2WSPFMTH95K8.pdf' does not exist. How do I obtain the full path of this PDF file?
2 replies
FFilament
Created by Gaurav on 6/6/2024 in #❓┊help
Auto delete export files after 7 days
How can I auto-delete export files (CSV and XLSX) as well as Import Failure CSV after 7 days from their creation?
2 replies
FFilament
Created by Gaurav on 6/6/2024 in #❓┊help
Transform record before import to database
I wish to store a list of CSV columns as a JSON object in a single column of database. What is the best way to do it? I want to store the following 3 columns of CSV: price, quantity, and brokerage as a JSON object in the data column of the record. I've tried setting the value in beforeFill as below, but it doesn't work.
protected function beforeFill()
{
$this->data['data'] = [
'price' => $this->data['price'],
'brokerage' => $this->data['brokerage'],
'quantity' => $this->data['quantity'],
];
unset(
$this->data['price'],
$this->data['brokerage'],
$this->data['quantity'],
);
}
protected function beforeFill()
{
$this->data['data'] = [
'price' => $this->data['price'],
'brokerage' => $this->data['brokerage'],
'quantity' => $this->data['quantity'],
];
unset(
$this->data['price'],
$this->data['brokerage'],
$this->data['quantity'],
);
}
3 replies
FFilament
Created by Gaurav on 6/5/2024 in #❓┊help
Need to click twice to save
I'm using a simple resource (pop-up form) for a resource which has a few live numeric fields, and a Placeholder field to display the calculated value. Every time I go about editing a record, I have to click twice on the save button for it to work. Is this a known issue? Is there a workaround?
2 replies
FFilament
Created by Gaurav on 6/3/2024 in #❓┊help
login page not found in production
Hello, I've deployed a very simple filament app to production, based on laravel 11. Since the new version of laravel doesn't come with auth, so I simply used filament login instead. Now, while the app seems to work alright in local development environment, when deployed to production, I'm getting 404 on /login route. How do I ensure that filament auth is available on /login page?
6 replies
FFilament
Created by Gaurav on 6/3/2024 in #❓┊help
fillForm on Create Page?
I've created a duplicate action as below:
Tables\Actions\CreateAction::make('Duplicate')
->label('Duplicate')
->icon('heroicon-o-document-duplicate')
->form(fn (Form $form) => static::form($form->model(static::$model))->columns(2))
->fillForm(fn ($record) => $record->toArray()),
Tables\Actions\CreateAction::make('Duplicate')
->label('Duplicate')
->icon('heroicon-o-document-duplicate')
->form(fn (Form $form) => static::form($form->model(static::$model))->columns(2))
->fillForm(fn ($record) => $record->toArray()),
Now, while this works alright for a simple resource (pop-up forms), it doesn't fill the form in case of regular resource (individual create / edit pages). What should I do differently for it to work for regular resource?
30 replies
FFilament
Created by Gaurav on 5/31/2024 in #❓┊help
Calculated input field in a form
I wish to include a calculated input field in a form, which is sum of a number of fields, some of which are dynamically included based on an attribute of the record. Although, I would calculate the value in the backend, I want to have the calculated value shown in the form itself while creation. I've tried evaluate() method as well as state() method both of which give Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization Is there a way to include such calculated fields? Alternatively, how I can I include custom javascript only for the form of a particular resource? As then I can calculate the field value via javascript.
63 replies
FFilament
Created by Gaurav on 5/30/2024 in #❓┊help
filament.exports.download giving 404 in multi-database multi-tenancy setup
I am using stancl/tenancy for multi database tenancy with filament. I've not enabled tenant features of filament itself, and instead relying on domain based tenancy provided by stancl/tenancy. I'm using the following configuration for tenancy:
'filesystem' => [
'suffix_base' => 'tenant/',
'suffix_storage_path' => true,
'asset_helper_tenancy' => false,
],
'filesystem' => [
'suffix_base' => 'tenant/',
'suffix_storage_path' => true,
'asset_helper_tenancy' => false,
],
In addition I'm using a custom FileUrlMiddleware with the following in handle method:
config()->set(
'filesystems.disks.public.url',
url('/' . config('tenancy.filesystem.suffix_base') . tenant('id'))
);
config()->set(
'filesystems.disks.public.url',
url('/' . config('tenancy.filesystem.suffix_base') . tenant('id'))
);
This middleware is being used in routes/tenant.php, config/livewire.php, as well as in the TenantAdminPanelProvider Also, during tenancy creation I'm setting the tenant public paths using a job, as below:
$this->tenant->run(function ($tenant) {
$storage_path = storage_path();

$suffixBase = config('tenancy.filesystem.suffix_base');

if (!is_dir(public_path($suffixBase))) {
@mkdir(public_path($suffixBase), 0777, true);
}

if (!is_dir($storage_path)) {
@mkdir("{$storage_path}/app/public", 0777, true);
@mkdir("{$storage_path}/framework/cache", 0777, true);

symlink("{$storage_path}/app/public", public_path("{$suffixBase}{$tenant->id}"));
}
});
$this->tenant->run(function ($tenant) {
$storage_path = storage_path();

$suffixBase = config('tenancy.filesystem.suffix_base');

if (!is_dir(public_path($suffixBase))) {
@mkdir(public_path($suffixBase), 0777, true);
}

if (!is_dir($storage_path)) {
@mkdir("{$storage_path}/app/public", 0777, true);
@mkdir("{$storage_path}/framework/cache", 0777, true);

symlink("{$storage_path}/app/public", public_path("{$suffixBase}{$tenant->id}"));
}
});
Base on this, all uploads for import are working fine, and data is getting imported alright. Similarly, when I'm trying to export the data, the files are getting created alright, such as: storage/tenant/0f7a82c3-f357-44f2-86c8-8e49e5bdc18f/app/public/filament_exports/1/0000000000000001.csv which is linked from public/tenant/0f7a82c3-f357-44f2-86c8-8e49e5bdc18f/filament_exports/1/0000000000000001.csv thanks to the above code. However, the path http://tenant.app.test/filament/exports/1/download?format=csv is giving 404.
3 replies
FFilament
Created by Gaurav on 5/29/2024 in #❓┊help
Specifying navigation items order within navigation groups
How do I specify the navigation items order withing navigation groups? I can order the navigation groups inside the panel using navigationGroups() method on the panel. However, how do I order individual navigation items within each of these navigation groups?
4 replies
FFilament
Created by Gaurav on 5/29/2024 in #❓┊help
Authorize Imports: Apply different policy methods on create and update
I am using authorize method for Importer to show it only to the users that have create authorization (via policy) for the respective model. However, as I'm setting records to be updated if a matching key already exists, I want update policy authorization to be checked for in such cases. How can I apply update authorization in such cases? Basically, I want authorization method to differ depending on whether a new record is being created or an existing record is being updated
1 replies
FFilament
Created by Gaurav on 5/29/2024 in #❓┊help
Replicate action: load form instead of save
I was searching for a way to add Clone table action, and came across Replicate action. The only difference between what I want and what this action offers is that, instead of saving the record directly, I want it to be loaded in the form instead, to be saved as a new record when Save button is clicked. Is there a way to do this with Replicate action, or is there some other action to achieve this? I'm looking for a Save As action to be precise.
3 replies
FFilament
Created by Gaurav on 3/7/2024 in #❓┊help
How to specify ignoreRecord in unique rule in Import?
I've added an import action to a model with option to update existing record via firstOrNew method. Now, I wish to have the unique rule applied on a column, but only when the record is not being updated with the same value. Typical laravel way for this is to ignore record with matching id. However, how do I specify this in the rules() parameter for a column in getColumns method of an Importer?
4 replies
FFilament
Created by Gaurav on 3/7/2024 in #❓┊help
ImportPolicy
I wish to authorize imports of models based on model specific permissions. How can I control it using ImportPolicy? For example, I've explicitly given a permission users.create to a particular role. Now, I wish only the users with that role to be able to import users data. Similarly, a roles.create permission exists for some other roles. And users with those roles should be able to import roles data.
3 replies