Jappi00
Jappi00
FFilament
Created by Jappi00 on 10/31/2023 in #❓┊help
Set Tenant Context in Queues and Crons
Hello together, I currently try to support multi tenancy in my application and I wounder what is the best practice to work with it in queues and crons. I have some Actions which can be triggerd from queueus, crons and the panel. The panel topic is working but in the queue and cron part I have some problems. I have tried to archive to set the tenant with the following code:
Filament::setTenant(Team::find(1));

Filament::getTenant()
Filament::setTenant(Team::find(1));

Filament::getTenant()
But it seems it needs an authenticated user. Because this is missing I receiving this error in Tinkerwell:
TYPE ERROR Filament\Events\TenantSet::__construct(): Argument #2 ($user) must be of type Illuminate\Database\Eloquent\Model|Illuminate\Contracts\Auth\Authenticatable|Filament\Models\Contracts\HasTenants, null given, called in vendor/filament/filament/src/FilamentManager.php on line 647 in phar:///Applications/Tinkerwell.app/Contents/Resources/tinkerwell/tinker.phar/vendor/psy/psysh/src/Exception/TypeErrorException.php on line 20.
TYPE ERROR Filament\Events\TenantSet::__construct(): Argument #2 ($user) must be of type Illuminate\Database\Eloquent\Model|Illuminate\Contracts\Auth\Authenticatable|Filament\Models\Contracts\HasTenants, null given, called in vendor/filament/filament/src/FilamentManager.php on line 647 in phar:///Applications/Tinkerwell.app/Contents/Resources/tinkerwell/tinker.phar/vendor/psy/psysh/src/Exception/TypeErrorException.php on line 20.
So I have tried to login the user before and it worked but I don't think taking the first user of a team is not the best practice:
Auth::loginUsingId(User::find(1)->id);
Auth::loginUsingId(User::find(1)->id);
I'am not very happy with this solution. Does anybody have a hint?
1 replies
FFilament
Created by Jappi00 on 9/6/2023 in #❓┊help
Dynamic Wizard Step
Hello together, I have a problem and no idea how i can solve it. Basically I currently using this https://filamentphp.com/docs/3.x/forms/advanced#dynamic-fields-based-on-a-select-option to show different forms based on an select and fill an json field with this data. Now I want to apply the same method to wizards to add a dynamic schema to an wizard step. I'am currently getting this error Call to a member function getChildComponentContainer() on null. I think it does not find the getComponent because it is not in the scope of the first step. The getSteps function looks like this:
protected function getSteps(): array

{

return [

Step::make('General')

->description('Configure general informations')

->schema([

Select::make('template_id')

->required()

->relationship('template', 'name')

->live()

->afterStateUpdated(fn (Select $component) => $component

->getContainer()

->getComponent('dynamicService')

->getChildComponentContainer()

->fill()

),

]),

Step::make('Service')

->description('Configure service informations')

->schema(fn (Get $get): array => $get('template_id') ? \Aura::getServiceByKey(Template::find($get('template_id')))::getTemplateForm() : [])

->key('dynamicService')

];

}
protected function getSteps(): array

{

return [

Step::make('General')

->description('Configure general informations')

->schema([

Select::make('template_id')

->required()

->relationship('template', 'name')

->live()

->afterStateUpdated(fn (Select $component) => $component

->getContainer()

->getComponent('dynamicService')

->getChildComponentContainer()

->fill()

),

]),

Step::make('Service')

->description('Configure service informations')

->schema(fn (Get $get): array => $get('template_id') ? \Aura::getServiceByKey(Template::find($get('template_id')))::getTemplateForm() : [])

->key('dynamicService')

];

}
1 replies