PHP code example of leek / filament-subtenant-scope
1. Go to this page and download the library: Download leek/filament-subtenant-scope library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
leek / filament-subtenant-scope example snippets
use Filament\Panel;
use Leek\FilamentSubtenantScope\SubtenantScope;
use Leek\FilamentSubtenantScope\SubtenantScopingPlugin;
use App\Models\ServiceArea;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(
SubtenantScopingPlugin::make()
->scopes([
SubtenantScope::make('service_area', 'Service Area', ServiceArea::class, 'service_area_id')
->icon('heroicon-o-map-pin')
->labelAttribute('name')
->optionsQuery(fn ($user) => ServiceArea::query()
->where('company_id', $user->company_id)
->where('is_active', true)
->orderBy('name')),
]),
);
}
use Filament\Resources\Resource;
use Leek\FilamentSubtenantScope\Concerns\HasSubtenantScopes;
class AppointmentResource extends Resource
{
use HasSubtenantScopes;
/** @var array<string, string|null> */
protected static array $subTenantScopes = [
'service_area' => 'service_area_id',
];
}
class ClientProfileResource extends Resource
{
use HasSubtenantScopes;
protected static array $subTenantScopes = ['service_area' => null];
public static function scopeSubTenantServiceArea(Builder $query, int $id): void
{
$query->where(function ($q) use ($id) {
$q->where('primary_service_area_id', $id)
->orWhereHas('serviceAreas', fn ($q) => $q->where('service_areas.id', $id));
});
}
}