Skip to content

Commit

Permalink
Update Select.php
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Sep 9, 2023
1 parent 86b13ff commit a688551
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 18 deletions.
5 changes: 3 additions & 2 deletions docs/04-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 1 addition & 3 deletions docs/05-dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
// ...
}
Expand Down
42 changes: 42 additions & 0 deletions docs/10-tenancy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/layout/base.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
</head>
<body
class="fi-body min-h-screen overscroll-y-none bg-gray-50 font-normal text-gray-950 antialiased dark:bg-gray-950 dark:text-white"
class="fi-body min-h-screen bg-gray-50 font-normal text-gray-950 antialiased dark:bg-gray-950 dark:text-white"
>
{{ \Filament\Support\Facades\FilamentView::renderHook('panels::body.start') }}
Expand Down
7 changes: 3 additions & 4 deletions resources/views/components/layout/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
])
>
<x-filament-panels::topbar :navigation="$navigation" />
Expand Down
21 changes: 15 additions & 6 deletions resources/views/components/sidebar/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(),
])
Expand Down Expand Up @@ -85,6 +93,7 @@ class="-mx-1.5 ms-auto hidden lg:flex"

<nav
class="fi-sidebar-nav flex flex-col gap-y-7 overflow-y-auto overflow-x-hidden px-6 py-8"
style="scrollbar-gutter: stable"
>
{{ \Filament\Support\Facades\FilamentView::renderHook('panels::sidebar.nav.start') }}

Expand Down
7 changes: 5 additions & 2 deletions src/Pages/Auth/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Http\Responses\Auth\Contracts\LoginResponse;
use Filament\Models\Contracts\FilamentUser;
use Filament\Notifications\Notification;
use Filament\Pages\Concerns\InteractsWithFormActions;
use Filament\Pages\SimplePage;
Expand Down Expand Up @@ -73,10 +74,12 @@ public function authenticate(): ?LoginResponse
$this->throwFailureValidationException();
}

/** @var \Filament\Models\Contracts\FilamentUser $user */
$user = Filament::auth()->user();

if (! $user->canAccessPanel(Filament::getCurrentPanel())) {
if (
($user instanceof FilamentUser) &&
(! $user->canAccessPanel(Filament::getCurrentPanel()))
) {
Filament::auth()->logout();

$this->throwFailureValidationException();
Expand Down

0 comments on commit a688551

Please sign in to comment.