Gaurav
Gaurav
FFilament
Created by developer on 6/5/2024 in #❓┊help
same model policy: multiple resources
I think this question was for me. Here is a sample:
abstract class ModelPolicy
{
public static ?string $slug = 'models';

/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->hasPermission(static::$slug . '.index');
}

/**
* Determine whether the user can view the model.
*/
public function view(User $user, Model $model): bool
{
return $user->hasPermission(static::$slug . '.show');
}
abstract class ModelPolicy
{
public static ?string $slug = 'models';

/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->hasPermission(static::$slug . '.index');
}

/**
* Determine whether the user can view the model.
*/
public function view(User $user, Model $model): bool
{
return $user->hasPermission(static::$slug . '.show');
}
and then,
class AccountPolicy extends ModelPolicy
{
public static ?string $slug = 'accounts';

public function setOpeningBalance(User $user): bool
{
return $user->hasPermission('accounts.set-opening-balance');
}
}
class AccountPolicy extends ModelPolicy
{
public static ?string $slug = 'accounts';

public function setOpeningBalance(User $user): bool
{
return $user->hasPermission('accounts.set-opening-balance');
}
}
Here AccountPolicy has inherited all the methods from ModelPolicy with appropriate customizations through static variables. And custom policy method or overrides are specified in the derived policy, such as setOpeningBalance in this case.
13 replies
FFilament
Created by Gaurav on 5/30/2024 in #❓┊help
filament.exports.download giving 404 in multi-database multi-tenancy setup
Finally managed to solve this by copying the following lines in my routes/tenant.php:
Route::get('/filament/exports/{export}/download', DownloadExport::class)
->name('filament.exports.download')
->middleware('filament.actions');
Route::get('/filament/imports/{import}/failed-rows/download', DownloadImportFailureCsv::class)
->name('filament.imports.failed-rows.download')
->middleware('filament.actions');
Route::get('/filament/exports/{export}/download', DownloadExport::class)
->name('filament.exports.download')
->middleware('filament.actions');
Route::get('/filament/imports/{import}/failed-rows/download', DownloadImportFailureCsv::class)
->name('filament.imports.failed-rows.download')
->middleware('filament.actions');
3 replies
FFilament
Created by Gaurav on 6/6/2024 in #❓┊help
Transform record before import to database
Managed to solve it by appending the following code at the end of beforeFill:
if ($this->record) {
$this->record->data = $this->data['data'];
}
if ($this->record) {
$this->record->data = $this->data['data'];
}
3 replies
FFilament
Created by developer on 6/5/2024 in #❓┊help
same model policy: multiple resources
You can extend the policy to create new policies. That's what I do when I've to use polymorphism. Allows me to customize the policy for specific cases.
13 replies
FFilament
Created by Gaurav on 6/3/2024 in #❓┊help
fillForm on Create Page?
I am not explicitly calling save as that shall be done by the action itself
30 replies
FFilament
Created by Gaurav on 6/3/2024 in #❓┊help
fillForm on Create Page?
This works, just made a little change to the beforeReplicaSaved closure as:
->beforeReplicaSaved(function (Model $replica, array $data): void {
$replica->setRawAttributes($data);
}
->beforeReplicaSaved(function (Model $replica, array $data): void {
$replica->setRawAttributes($data);
}
30 replies
FFilament
Created by Gaurav on 6/3/2024 in #❓┊help
fillForm on Create Page?
I will give it a try and report back
30 replies
FFilament
Created by Gaurav on 6/3/2024 in #❓┊help
fillForm on Create Page?
2 things: 1. form(self::form()) doesn't work as self::form requires a from argument. So, I've used form(fn (Form $form) => static::form($form->model(static::$model))->columns(2)) instead 2. It creates a new record with old values, and updated the existing record with new values
30 replies
FFilament
Created by Gaurav on 6/3/2024 in #❓┊help
fillForm on Create Page?
Let me try this and get back
30 replies
FFilament
Created by Gaurav on 6/3/2024 in #❓┊help
fillForm on Create Page?
I believe there will be a couple of more steps required in case of a generic action, such as letting filament know what to do when the form has been filled, via some action buttons. May as well need to create a separate page for this, similar to edit page.
30 replies
FFilament
Created by Gaurav on 6/3/2024 in #❓┊help
fillForm on Create Page?
So, my mistake is only that I've used CreateAction?
30 replies
FFilament
Created by Gaurav on 6/3/2024 in #❓┊help
fillForm on Create Page?
Exactly what I was trying to do. The code I had shared in the original post does exactly that in a simple resource, but doesn't work when page change is involved
30 replies
FFilament
Created by Gaurav on 6/3/2024 in #❓┊help
fillForm on Create Page?
I meant a generic replica action which uses form method of the resource (thus available for all resources)
30 replies
FFilament
Created by Gaurav on 6/3/2024 in #❓┊help
fillForm on Create Page?
Wouldn't it be simpler (and more generic) to create a replica action which simply creates a copy of the current record (minus the id perhaps) and show it in create form?
30 replies
FFilament
Created by Gaurav on 6/3/2024 in #❓┊help
fillForm on Create Page?
Basically it's save as action, which needs to be triggered from the table record (different from Create & create another)
30 replies
FFilament
Created by Gaurav on 6/3/2024 in #❓┊help
fillForm on Create Page?
But that value needs to be inputted by the user. That's why I wished to show the record in the form so that user can change the value before saving.
30 replies
FFilament
Created by Gaurav on 6/5/2024 in #❓┊help
Need to click twice to save
Should I submit a bug report for this?
2 replies
FFilament
Created by Gaurav on 6/3/2024 in #❓┊help
fillForm on Create Page?
That's what I eventually ended up using. Though the reason I didn't want to was that in some cases plain replication would result in duplication of unique required attributes. I'm using simple resource (pop-up forms) in such cases. A better (more consistent) solution would be appreciated though.
30 replies
FFilament
Created by Gaurav on 6/3/2024 in #❓┊help
login page not found in production
Thanks! Actually what fixed it was php artisan queue:restart
6 replies
FFilament
Created by Benjamin on 6/5/2024 in #❓┊help
DatePicker/DateTimePicker alternative with manual typing support
It is. That's where I'm at a loss too.
14 replies