From a6885512f3607f614d5506f6d7858dc643aa09aa Mon Sep 17 00:00:00 2001 From: Dan Date: Sat, 9 Sep 2023 23:05:41 +0000 Subject: [PATCH] Update Select.php --- docs/04-pages.md | 5 ++- docs/05-dashboard.md | 4 +- docs/10-tenancy.md | 42 +++++++++++++++++++ .../views/components/layout/base.blade.php | 2 +- .../views/components/layout/index.blade.php | 7 ++-- .../views/components/sidebar/index.blade.php | 21 +++++++--- src/Pages/Auth/Login.php | 7 +++- 7 files changed, 70 insertions(+), 18 deletions(-) diff --git a/docs/04-pages.md b/docs/04-pages.md index f71c58b0..f4e67d46 100644 --- a/docs/04-pages.md +++ b/docs/04-pages.md @@ -68,11 +68,12 @@ protected function getHeaderActions(): array If you're using actions on an [Edit](resources/editing-records) or [View](resources/viewing-records) resource page, you can refresh data within the main form using the `refreshFormData()` method: ```php +use App\Models\Post; use Filament\Actions\Action; Action::make('approve') - ->action(function () { - $this->getRecord()->approve(); + ->action(function (Post $record) { + $record->approve(); $this->refreshFormData([ 'status', diff --git a/docs/05-dashboard.md b/docs/05-dashboard.md index 875b43fc..791039b7 100644 --- a/docs/05-dashboard.md +++ b/docs/05-dashboard.md @@ -133,9 +133,7 @@ If you want to customize the dashboard class, for example, to [change the number namespace App\Filament\Pages; -use Filament\Pages\Dashboard as BasePage; - -class Dashboard extends BasePage +class Dashboard extends \Filament\Pages\Dashboard { // ... } diff --git a/docs/10-tenancy.md b/docs/10-tenancy.md index 61e0f635..072fad1c 100644 --- a/docs/10-tenancy.md +++ b/docs/10-tenancy.md @@ -8,6 +8,48 @@ Multi-tenancy is a concept where a single instance of an application serves mult Multi-tenancy is a very sensitive topic. It's important to understand the security implications of multi-tenancy and how to properly implement it. If implemented partially or incorrectly, data belonging to one tenant may be exposed to another tenant. Filament provides a set of tools to help you implement multi-tenancy in your application, but it is up to you to understand how to use them. Filament does not provide any guarantees about the security of your application. It is your responsibility to ensure that your application is secure. Please see the [security](#tenancy-security) section for more information. +## Simple one-to-many tenancy + +The term "multi-tenancy" is broad and may mean different things in different contexts. Filament's tenancy system implies that the user belongs to **many** tenants (*organizations, teams, companies, etc.*) and may switch between them. + +If your case is simpler and you don't need a many-to-many relationship, then you don't need to set up the tenancy in Filament. You could use [observers](https://laravel.com/docs/eloquent#observers) and [global scopes](https://laravel.com/docs/eloquent#global-scopes) instead. + +Let's say you have a database column `users.team_id`, you can scope all records to have the same `team_id` as the user using a [global scope](https://laravel.com/docs/eloquent#global-scopes): + +```php +use Illuminate\Database\Eloquent\Builder; + +class Post extends Model +{ + protected static function booted(): void + { + if (auth()->check()) { + static::addGlobalScope('team', function (Builder $query) { + $query->where('team_id', auth()->user()->team_id); + // or with a `team` relationship defined: + $query->whereBelongsTo(auth()->user()->team); + }); + } + } +} +``` + +To automatically set the `team_id` on the record when it's created, you can create an [observer](https://laravel.com/docs/eloquent#observers): + +```php +class PostObserver +{ + public function creating(Post $post): void + { + if (auth()->check()) { + $post->team_id = auth()->user()->team_id; + // or with a `team` relationship defined: + $post->team()->associate(auth()->user()->team); + } + } +} +``` + ## Setting up tenancy To set up tenancy, you'll need to specify the "tenant" (like team or organization) model in the [configuration](configuration): diff --git a/resources/views/components/layout/base.blade.php b/resources/views/components/layout/base.blade.php index 10842173..c20f17cc 100644 --- a/resources/views/components/layout/base.blade.php +++ b/resources/views/components/layout/base.blade.php @@ -90,7 +90,7 @@ {{ \Filament\Support\Facades\FilamentView::renderHook('panels::body.start') }} diff --git a/resources/views/components/layout/index.blade.php b/resources/views/components/layout/index.blade.php index 6fc3982a..5d2e70de 100644 --- a/resources/views/components/layout/index.blade.php +++ b/resources/views/components/layout/index.blade.php @@ -19,21 +19,20 @@ class="fi-sidebar-close-overlay fixed inset-0 z-30 bg-gray-950/50 transition dur @if (filament()->isSidebarCollapsibleOnDesktop()) x-data="{}" x-bind:class="{ - 'lg:ps-[--collapsed-sidebar-width]': ! $store.sidebar.isOpen, - 'fi-main-ctn-sidebar-open lg:ps-[--sidebar-width]': $store.sidebar.isOpen, + 'fi-main-ctn-sidebar-open': $store.sidebar.isOpen, }" x-bind:style="'display: flex'" {{-- Mimics `x-cloak`, as using `x-cloak` causes visual issues with chart widgets --}} @elseif (filament()->isSidebarFullyCollapsibleOnDesktop()) x-data="{}" x-bind:class="{ - 'fi-main-ctn-sidebar-open lg:ps-[--sidebar-width]': $store.sidebar.isOpen, + 'fi-main-ctn-sidebar-open': $store.sidebar.isOpen, }" x-bind:style="'display: flex'" {{-- Mimics `x-cloak`, as using `x-cloak` causes visual issues with chart widgets --}} @endif @class([ 'fi-main-ctn w-screen flex-1 flex-col', 'hidden h-full transition-all' => filament()->isSidebarCollapsibleOnDesktop() || filament()->isSidebarFullyCollapsibleOnDesktop(), - 'flex lg:ps-[--sidebar-width]' => ! (filament()->isSidebarCollapsibleOnDesktop() || filament()->isSidebarFullyCollapsibleOnDesktop() || filament()->hasTopNavigation()), + 'flex' => ! (filament()->isSidebarCollapsibleOnDesktop() || filament()->isSidebarFullyCollapsibleOnDesktop() || filament()->hasTopNavigation()), ]) > diff --git a/resources/views/components/sidebar/index.blade.php b/resources/views/components/sidebar/index.blade.php index fd53ae4d..fc544eb8 100644 --- a/resources/views/components/sidebar/index.blade.php +++ b/resources/views/components/sidebar/index.blade.php @@ -3,7 +3,7 @@ ]) @php - $openSidebarClasses = 'fi-sidebar-open max-w-none translate-x-0 shadow-xl ring-1 ring-gray-950/5 rtl:-translate-x-0 dark:ring-white/10'; + $openSidebarClasses = 'fi-sidebar-open w-[--sidebar-width] translate-x-0 shadow-xl ring-1 ring-gray-950/5 rtl:-translate-x-0 dark:ring-white/10'; $isRtl = __('filament-panels::layout.direction') === 'rtl'; @endphp @@ -13,19 +13,27 @@ x-cloak x-bind:class=" $store.sidebar.isOpen - ? @js($openSidebarClasses) - : 'lg:max-w-[--collapsed-sidebar-width] -translate-x-full rtl:translate-x-full lg:translate-x-0 rtl:lg:-translate-x-0' + ? @js($openSidebarClasses . 'lg:sticky') + : '-translate-x-full rtl:translate-x-full lg:sticky lg:translate-x-0 rtl:lg:-translate-x-0' " @else - @if (filament()->hasTopNavigation() || filament()->isSidebarFullyCollapsibleOnDesktop()) + @if (filament()->hasTopNavigation()) x-cloak + x-bind:class="$store.sidebar.isOpen ? @js($openSidebarClasses) : '-translate-x-full rtl:translate-x-full'" + @elseif (filament()->isSidebarFullyCollapsibleOnDesktop()) + x-cloak + x-bind:class="$store.sidebar.isOpen ? @js($openSidebarClasses . 'lg:sticky') : '-translate-x-full rtl:translate-x-full'" @else x-cloak="-lg" + x-bind:class=" + $store.sidebar.isOpen + ? @js($openSidebarClasses . 'lg:sticky') + : 'w-[--sidebar-width] -translate-x-full rtl:translate-x-full lg:sticky' + " @endif - x-bind:class="$store.sidebar.isOpen ? @js($openSidebarClasses) : '-translate-x-full rtl:translate-x-full'" @endif @class([ - 'fi-sidebar fixed inset-y-0 start-0 z-30 grid h-screen w-[--sidebar-width] content-start bg-white transition-all dark:bg-gray-900 lg:z-0 lg:bg-transparent lg:shadow-none lg:ring-0 dark:lg:bg-transparent', + 'fi-sidebar fixed inset-y-0 start-0 z-30 grid h-screen content-start bg-white transition-all dark:bg-gray-900 lg:z-0 lg:bg-transparent lg:shadow-none lg:ring-0 lg:transition-none dark:lg:bg-transparent', 'lg:translate-x-0 rtl:lg:-translate-x-0' => ! (filament()->isSidebarCollapsibleOnDesktop() || filament()->isSidebarFullyCollapsibleOnDesktop() || filament()->hasTopNavigation()), 'lg:-translate-x-full rtl:lg:translate-x-full' => filament()->hasTopNavigation(), ]) @@ -85,6 +93,7 @@ class="-mx-1.5 ms-auto hidden lg:flex"