Wim
Multi-tenant: search across all products
Hmmm, stupid I did not think about it, but it works
->getSearchResultsUsing(function ($search) {
if (strlen($search) < 3) {
return [];
}
return Product::where('name', 'like', "%{$search}%")->withoutGlobalScope('organization')
->limit(50)
->get()
->pluck('name', 'id');
})
11 replies
Multi-tenant: search across all products
It might be because it's Friday eve here, but how would I be able to combine the below. The first one is what is existing already and the second one I need to add.
public static function getEloquentQuery(): Builder
{
return Topic::query();
}
public static function getEloquentQuery(): Builder
{
return Product::query()->withoutGlobalScope('organization');
}
11 replies
Multi-tenant: search across all products
Confused a bit:
1) Not having a
static::addGlobalScope
on the Product Model works
2) Having a static::addGlobalScope
on the Product Model does not give all products (which is understandable). Overwriting public static function isScopedToTenant()
to false, it not giving all the products.
3) Having a static::addGlobalScope
on the Product Model and overwrite the getEloquentQuery()
in the MessageResource is sth I cannot do as it is already used for the MessageResource (the retrieval of the products is done in the MessageResource and there is already a getEloquentQuery()
in place)
4) When I nevertheless add the getEloquentQuery()
with a return Animal::query()->withoutGlobalScope('organization');
I get only the Products belonging to the organization again.11 replies
Redirect to app panel instead of admin panel
Correct, there is a $this->redirect(Dashboard::getURL()). But as said, that redirects to the Admin panel (as it's the default()). What I would like is that it redirects to the App panel.
I have 'fixed' it as follows:
if (Filament::getPanel()->getId() === 'admin') {
Filament::getPanel('app')->auth()->login($user);
$this->redirect(route('filament.app.resources.products.index', ['tenant' => $this->invitationModel->organization_id]));
session()->regenerate();
}
But this does not feel correct and efficient.
6 replies
Redirect to app panel instead of admin panel
In fact, when the invite user action I create an invitation entry in a table. Then the invited user clicks on the link in the mail and the following is executed
public function create(): void
{
$this->invitationModel = Invitation::find($this->invitation); $user = User::create([ 'name' => $this->form->getState()['name'], 'email' => $this->invitationModel->email, 'password' =>Hash::make($this->form->getState()['password']), ]); $user->organizations()->attach($this->invitationModel->organization_id); auth()->login($user); //this one goes to admin panel because it's default() but I need it to go to app (user) panel $this->redirect(Dashboard::getUrl()); }
$this->invitationModel = Invitation::find($this->invitation); $user = User::create([ 'name' => $this->form->getState()['name'], 'email' => $this->invitationModel->email, 'password' =>Hash::make($this->form->getState()['password']), ]); $user->organizations()->attach($this->invitationModel->organization_id); auth()->login($user); //this one goes to admin panel because it's default() but I need it to go to app (user) panel $this->redirect(Dashboard::getUrl()); }
6 replies
Redirect to app panel instead of admin panel
Like this one: https://www.youtube.com/watch?v=YpK16Z6Hr14&t=85s
6 replies
Favorite products: many to many not working
Thanks Povilas. I did follow your suggestion and found indeed something interesting. The query that gets executed is
I have a multi-tenancy setup and by default Filament is configured to only show the products that are part of the organization tenant.
When I change the products (manually in the database) to belong to the logged in organization, the data will show correctly. When the products belong to other organizations, the information does not show.
I have a middleware as follows:
Not sure if there is a way to apply the global scope to all resources, except Favorites? Or perhaps there's better suggestions?
Tried with in the FavoriteResource but does not work
4 replies