rupadana / filament-api-service

A simple api service for supporting filamentphp
https://filamentphp.com/plugins/rupadana-api-service
MIT License
95 stars 22 forks source link

added tenant aware api feature #23

Closed eelco2k closed 4 months ago

eelco2k commented 4 months ago

Added the ability to scope API resources to be Filament tenant aware. By default the tenant-awareness is disabled in the config.

maxwellmezadre commented 4 months ago

up

rupadana commented 4 months ago

Thank you for your contribution @eelco2k appreciate it.

But i have a question, what goals between the tenancy.is_tenant_aware and tenancy.enabled config?

because i think this package is for API purpose, we can use tenancy.enabled only. Istead of adding a more config.

eelco2k commented 4 months ago

what i also will do is refactor and not put the trait on the model, but on the handlers. that way you don't have to add the trait manually to the model but it's already configured in the handler stubs.

I will try to reuse:

public static function scopeEloquentQueryToTenant(Builder $query, ?Model $tenant): Builder

and 

 protected static bool $isScopedToTenant = true;

But because you're using spatie query builder i have to change it a little bit.

rupadana commented 4 months ago

what i also will do is refactor and not put the trait on the model, but on the handlers. that way you don't have to add the trait manually to the model but it's already configured in the handler stubs.

I will try to reuse:

public static function scopeEloquentQueryToTenant(Builder $query, ?Model $tenant): Builder

and 

 protected static bool $isScopedToTenant = true;

But because you're using spatie query builder i have to change it a little bit.

thats will be great for performance, because the model isnt execute the bootHasApiTenantScope method anymore if the model used outside of the Handlers.

rupadana commented 4 months ago

let merge to dev version first

rupadana commented 4 months ago

@eelco2k can you test the dev branch? and please give some screenshot of your test.

Update the composer.json

"rupadana/filament-api-support": "dev-dev"

Thank You.