Roland Barkóczi
Roland Barkóczi
FFilament
Created by Roland Barkóczi on 12/6/2024 in #❓┊help
test relationmanager CreateAction
Hello guys, could somebody submit some example code how to test a relation manager create action? - how to fill the form, how to submit the form? Based on the documentation here: i wrote this test, but it fails, cannot see the text:
$this->actingAs($user)
->get(EventResource::getUrl('view', ['tenant' => $tenant->slug, 'record' => $event->id]))
->assertSuccessful();

livewire(EventResource\RelationManagers\AttendeeRelationManager::class,
[
'ownerRecord' => $event,
'pageClass' => EventResource\Pages\ViewEvent::class,
])
->assertSuccessful()
->mountAction(CreateAction::class)
->assertSee('Create Attendee');
$this->actingAs($user)
->get(EventResource::getUrl('view', ['tenant' => $tenant->slug, 'record' => $event->id]))
->assertSuccessful();

livewire(EventResource\RelationManagers\AttendeeRelationManager::class,
[
'ownerRecord' => $event,
'pageClass' => EventResource\Pages\ViewEvent::class,
])
->assertSuccessful()
->mountAction(CreateAction::class)
->assertSee('Create Attendee');
4 replies
FFilament
Created by Roland Barkóczi on 12/3/2024 in #❓┊help
PhpStan error on $this->resolveRecord($record)
Hello All, I run phpstan on my code regularly, and I stumbled upon the following issue. This code excerpt is from a page definition
class PosMenuPage extends Page{
...
/**
* @var PointOfSale|int|string|null
*/
public Model|string|int|null $record;

public function mount(int | string $record): void
{
$this->record = $this->resolveRecord($record);
$this->categories = $this->record->merchant->categories()
...
class PosMenuPage extends Page{
...
/**
* @var PointOfSale|int|string|null
*/
public Model|string|int|null $record;

public function mount(int | string $record): void
{
$this->record = $this->resolveRecord($record);
$this->categories = $this->record->merchant->categories()
...
Phpstan reports the following for the last row:
Access to an undefined property Illuminate\Database\Eloquent\Model::$merchant.
Even I declared the $record type in the docblock, the resolveRecord return type is a Model, and phpstan can't recognize the merchant belongsTo relation. Of course I can re-implement the resolveRecord function in my class and typehint with the correct return type, but I feel this is just add unnecessary bloat to my code. How can I typehint this function to pass the phpstan?
1 replies
FFilament
Created by Roland Barkóczi on 11/24/2024 in #❓┊help
Customize relationManager authorization
Hello guys, how can I customize a relationManager authorization? Use case: I have an event (of an organization) and there are employees assigned to events who can have different permissions. The EventResource has different relations (Attendees, PointOfSales, etc), and I want to control the authorization of these relations, but I need the event id in the Policies. How could I inject the current ownerRecord to the Policy methods, eg: viewAny($user, Event $event) of edit($user, $attendee, $event) ?
3 replies
FFilament
Created by Roland Barkóczi on 10/31/2024 in #❓┊help
How should I define the exportAction exporter class in order to export hasMany relation?
Use case: - I have a Product model, product has many prices.
public function prices(): HasMany
{
return $this->hasMany(ProductPrice::class, 'product_id');
}
public function prices(): HasMany
{
return $this->hasMany(ProductPrice::class, 'product_id');
}
I would like to export these prices in csv/excel format. Ideally add these values in separate columns: SKU | PRODUCT_NAME | ..... | Price 1 | Price 2 | Could you help me on this topic?
5 replies
FFilament
Created by Roland Barkóczi on 10/21/2024 in #❓┊help
Notification::duration() has no effect
I try to set the duration of a Notification, but if I set any value for duration, it disappear after ~6 sec, even if I add the persisitent() function. Can it be a bug or I missed something?
3 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
I have the following models Product - id - name Pricelist - id - name ProductPrice - id - product_id - pricelist_id - price I want to create a dynamic table on product listing page, where all the Pricelist are listed as columns (e.g. Retail, Reseller, Discount) and respectively the belonging product prices. I defined these functions in Product model:
public function prices(): HasMany
{
return $this->hasMany(ProductPrice::class, 'product_id');
}

public function price($pricelist_id)
{
return $this->prices()->where('pricelist_id', $pricelist_id)->first();
}
public function prices(): HasMany
{
return $this->hasMany(ProductPrice::class, 'product_id');
}

public function price($pricelist_id)
{
return $this->prices()->where('pricelist_id', $pricelist_id)->first();
}
Furthermore I tried this code in the ProductRelationsManager table columns function:
...array_map(
fn(Pricelist $pricelist) => TextColumn::make('price_' . $pricelist->id)
->label($pricelist->name), $this->getOwnerRecord()->pricelists()->get()->all())
...array_map(
fn(Pricelist $pricelist) => TextColumn::make('price_' . $pricelist->id)
->label($pricelist->name), $this->getOwnerRecord()->pricelists()->get()->all())
So it creates all the pricelist columns, but I have no clue what should I add to the TextColumn::make() parameter in order to reach the given price belonging to the actual pricelist. Also have no clues how to define the form, what should I add to the TextInput::make() as parameter.
47 replies
FFilament
Created by Roland Barkóczi on 10/15/2024 in #❓┊help
Reuse Filament Login and Registration Form outside the panel
Hello Guys, Could you give me tips how can I replace the Breeze login and registration form with the filament ones? Can I point out the filament registration page in my routes/auth J
...
Volt::route('register', 'pages.auth.register')
->name('register');
...
...
Volt::route('register', 'pages.auth.register')
->name('register');
...
Or should I rework somehow the pages.auth.register blade template? Thanks in advance for your help!
2 replies
FFilament
Created by Roland Barkóczi on 10/14/2024 in #❓┊help
Policy depends on request path
Hello All, I have the following problem: I have a [event] resource and the resource view page have a couple of relations (eg. attendees, vendors, etc). I want to add policies to these relations, but to determine if the given user has access to an operation I need the event id {record}. I tried to reach the request route parameter (request()->route()->parameter('record');), it works, but when I change tab, the livewire call (livewire/update) behind the scene refresh the data and the given operation will be refused due to the livewire call does not have the {record} parameter in the url . As a workaround I thought to save the event_id to a session variable, but this will cause a problem when a user have multiple browser window with different event to view. Question how can I reach an URL parameter and make it available for the subsequent livewire calls?
7 replies
FFilament
Created by Roland Barkóczi on 5/20/2024 in #❓┊help
Spatie Media Library responsiveImages How to convert to webp?
I tried to google for it but I did not found: how can I configure this plugin or the underlying Laravel-medialibrary to store the responsive images in webp format instead of jpg ?
2 replies
FFilament
Created by Roland Barkóczi on 5/19/2024 in #❓┊help
spatie translatable how to define form schema in a correct way
Hello all, could you please give me guidance how suppose to define the form schema for the translatable fields? My issue: - if I add the localswitcher to the create and edit page, I define the schema as following:
return $form
->schema([
TextInput::make("name ")
->label(__('Name'))
->required()
->maxLength(255)

]);
return $form
->schema([
TextInput::make("name ")
->label(__('Name'))
->required()
->maxLength(255)

]);
But I receive the following validation error:
2 replies
FFilament
Created by Roland Barkóczi on 5/14/2024 in #❓┊help
Translation hasMany relation: how to populate form and field by locale
I have to a model: Category, it has a relation CategoryI10n which has a field: locale. In the Category model I defined the relation:
public function translations(){
return $this->hasMany(CategoryI10n::class);
}
public function translations(){
return $this->hasMany(CategoryI10n::class);
}
I iterate through the available locales, create tabs, and text fields: TextInput::make("name_$locale") Then in the CreateCategory.php I implemented a custom handleRecordCreation function, which creates the necessary records in the relation. But I have no clue, how to display only one translation record corresponds to the current record: - if I add TextColumn::make("translations.name"), it displays all the 3 available translations. - I tried to write a __get() function in Category model, if the property is name_en, name_fr it query the relation and give back the correct value. It works well in the tinker, but for some reason the TextColumn::make("name_en") does not call the __get() method. Can you help me here how would you handle this problem? Thank you in advance!
13 replies
FFilament
Created by Roland Barkóczi on 5/11/2024 in #❓┊help
How to listen enter key on TextInput and call callback function?
I would like to injext wire:keyup or wire:stream to a TextInput or Textarea.
5 replies
FFilament
Created by Roland Barkóczi on 5/11/2024 in #❓┊help
Update RichEditor based on other field
I would like to pre-populate a RichEditor field if another field changes: TextInput::make('Prompt') ->label(__('AI Assistant')) ->afterStateUpdated(function (Set $set,) { $set('content', 'Foobar'); }) ->live(onBlur: 500) ->columnSpan(2), RichEditor::make('content') ->required() ->columnSpanFull(), But it does not work. It works with a plain TextInput. What I'm doing wrong?
6 replies
FFilament
Created by Roland Barkóczi on 5/8/2024 in #❓┊help
user model with PK type string
I encountered with a rather strange bug: - I installed a fresh laravel 11 app, then I added the filement plugin, migrated the database, created a user, and I was able to log in to the panel without any issue. Because of business requirements, I want to change the User model primary key to uuid ($table->uuid('id')->primary(); in my migration file), I also added public $keyType = 'string'; public $incrementing = false; ... public static function boot() { parent::boot(); static::creating(function ($model) { $model->id = (string) uniqid("usr_"); }); } to my User model. Refreshed the database, recreated a new user, but after these changes I cannot log in anymore into the app. I debugged the app, the user record queried correctly at login, but it redirects back to the login screen, because in the vendor/filament/filament/src/Http/Middleware/Authenticate.php file, line 22: if (!$guard->check()) { $this->unauthenticated($request, $guards); return; } the $guard->check() returns null. Could you give me any clue, why it isn't working with PK type string?
15 replies