Skip to content

Ability to apply custom query #27

@Bouhnosaure

Description

@Bouhnosaure

Hi,

Thanks for this plugin, i currently have an issue with multi tenancy and global scopes as the .

For instance in the multi tenant mode i have a middleware that apply a global scope in order to prevent ajax requests to fetch other users in the select.

And when i want to switch to a different user from another entity i get a 404 because i'm still in the current entity

The workaround I've found is to add directly the withoutGlobalScope in src/FilamentDevelopersLogin.php

$model = (new ($plugin->getModelClass()))
    ->withoutGlobalScope('user_team') // <--- here
    ->where($plugin->getColumn(), $credentials)
    ->first();

But maybe some people will have another issue with this.

I don't know if a good way is to allow to add custom query builder clauses alongside the already present where($plugin->getColumn(), $credentials) or to make something that can replace it entirely.

With something like $plugin->getModelQuery() and in the PanelProvider use it like that

FilamentDeveloperLoginsPlugin::make()
  ->users(fn() => User::withoutGlobalScope('user_team')->pluck('email', 'name')->toArray())
  ->getModelQuery(fn(Builder $query) => $query->withoutGlobalScope('user_team')) // <--- here
  ->enabled(app()->environment('local'))

What do you think ?

Thanks,

Alex

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions