mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
wip
This commit is contained in:
@@ -340,6 +340,8 @@ public function panel(Panel $panel): Panel
|
||||
}
|
||||
```
|
||||
|
||||
For more information on creating a profile page, check out the [authentication features documentation](users#authentication-features).
|
||||
|
||||
### Customizing the logout link
|
||||
|
||||
To customize the user logout link at the end of the user menu, register a new item with the `logout` array key:
|
||||
|
||||
@@ -142,26 +142,64 @@ public function panel(Panel $panel): Panel
|
||||
->login()
|
||||
->registration()
|
||||
->passwordReset()
|
||||
->emailVerification();
|
||||
->emailVerification()
|
||||
->profile();
|
||||
}
|
||||
```
|
||||
|
||||
### Customizing the authentication features
|
||||
|
||||
If you'd like to replace these pages with your own, you can pass in a "route action" to any of these methods.
|
||||
If you'd like to replace these pages with your own, you can pass in any Filament page class to these methods.
|
||||
|
||||
A route action could be a callback function that gets executed when you visit the page, or the name of a controller, or a Livewire component - anything that works when using `Route::get()` in Laravel normally.
|
||||
|
||||
Most people will be able to make their desired customizations by extending the default Livewire class from the Filament codebase, overriding methods like `form()`, and then passing the new Livewire class in as the route action:
|
||||
Most people will be able to make their desired customizations by extending the base page class from the Filament codebase, overriding methods like `form()`, and then passing the new page class in to the configuration:
|
||||
|
||||
```php
|
||||
use App\Livewire\Auth\Login;
|
||||
use App\Filament\Pages\Auth\EditProfile;
|
||||
use Filament\Panel;
|
||||
|
||||
public function panel(Panel $panel): Panel
|
||||
{
|
||||
return $panel
|
||||
// ...
|
||||
->login(Login::class);
|
||||
->profile(EditProfile::class);
|
||||
}
|
||||
```
|
||||
|
||||
In this example, we will customize the profile page. We need to create a new PHP class at `app/Filament/Pages/Auth/EditProfile.php`:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages\Auth;
|
||||
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Pages\Auth\EditProfile as BaseEditProfile;
|
||||
|
||||
class EditProfile extends BaseEditProfile
|
||||
{
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
TextInput::make('username')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
$this->getNameFormComponent(),
|
||||
$this->getEmailFormComponent(),
|
||||
$this->getPasswordFormComponent(),
|
||||
$this->getPasswordConfirmationFormComponent(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This class extends the base profile page class from the Filament codebase. Other page classes you could extend include:
|
||||
|
||||
- `Filament\Pages\Auth\Login`
|
||||
- `Filament\Pages\Auth\Register`
|
||||
- `Filament\Pages\Auth\EmailVerification\EmailVerificationPrompt`
|
||||
- `Filament\Pages\Auth\PasswordReset\RequestPasswordReset`
|
||||
- `Filament\Pages\Auth\PasswordReset\ResetPassword`
|
||||
|
||||
In the `form()` method of the example, we call methods like `getNameFormComponent()` to get the default form components for the page. You can customize these components as required. For all the available customization options, see the base `EditProfile` page class in the Filament codebase - it contains all the methods that you can override to make changes.
|
||||
|
||||
@@ -54,9 +54,9 @@ class User extends Authenticatable implements FilamentUser, HasTenants
|
||||
|
||||
In this example, users belong to many teams, so there is a `teams()` relationship. The `getTenants()` method returns the teams that the user belongs to. Filament uses this to list the tenants that the user has access to.
|
||||
|
||||
You'll also want users to be able to [register new teams](#registration).
|
||||
You'll also want users to be able to [register new teams](#adding-a-tenant-registration-page).
|
||||
|
||||
## Registration
|
||||
## Adding a tenant registration page
|
||||
|
||||
A registration page will allow users to create a new tenant.
|
||||
|
||||
@@ -115,11 +115,61 @@ public function panel(Panel $panel): Panel
|
||||
}
|
||||
```
|
||||
|
||||
### Customizing the registration page
|
||||
### Customizing the tenant registration page
|
||||
|
||||
You can override anything you want on the registration page class to make it act as you want. Even the `$view` property can be overridden to use a custom view.
|
||||
You can override any method you want on the base registration page class to make it act as you want. Even the `$view` property can be overridden to use a custom view of your choice.
|
||||
|
||||
Alternatively, you can pass any route action to the `tenantRegistration()` method. That could be a callback function that gets executed when you visit the page, or the name of a controller, or a Livewire component - anything that works when using `Route::get()` in Laravel normally.
|
||||
## Adding a tenant profile page
|
||||
|
||||
A profile page will allow users to edit information about the tenant.
|
||||
|
||||
To set up a profile page, you'll need to create a new page class that extends `Filament\Pages\Tenancy\EditTenantProfile`. This is a full-page Livewire component. You can put this anywhere you want, such as `app/Filament/Pages/Tenancy/EditTeamProfile.php`:
|
||||
|
||||
```php
|
||||
namespace App\Filament\Pages\Tenancy;
|
||||
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Pages\Tenancy\EditTenantProfile;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EditTeamProfile extends EditTenantProfile
|
||||
{
|
||||
public static function getLabel(): string
|
||||
{
|
||||
return 'Team profile';
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
TextInput::make('name'),
|
||||
// ...
|
||||
]);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You may add any [form components](../forms/getting-started) to the `form()` method. They will get saved directly to the tenant model.
|
||||
|
||||
Now, we need to tell Filament to use this page. We can do this in the [configuration](configuration):
|
||||
|
||||
```php
|
||||
use App\Filament\Pages\Tenancy\RegisterTeam;
|
||||
use Filament\Panel;
|
||||
|
||||
public function panel(Panel $panel): Panel
|
||||
{
|
||||
return $panel
|
||||
// ...
|
||||
->tenantProfile(RegisterTeam::class);
|
||||
}
|
||||
```
|
||||
|
||||
### Customizing the tenant profile page
|
||||
|
||||
You can override any method you want on the base profile page class to make it act as you want. Even the `$view` property can be overridden to use a custom view of your choice.
|
||||
|
||||
## Accessing the current tenant
|
||||
|
||||
@@ -238,7 +288,7 @@ public function panel(Panel $panel): Panel
|
||||
MenuItem::make()
|
||||
->label('Settings')
|
||||
->url(route('filament.pages.settings'))
|
||||
->icon('heroicon-m-cog-6-tooth'),
|
||||
->icon('heroicon-m-cog-8-tooth'),
|
||||
// ...
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Filament\Panel\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Pages\Auth\EditProfile;
|
||||
use Filament\Pages\Auth\EmailVerification\EmailVerificationPrompt;
|
||||
use Filament\Pages\Auth\Login;
|
||||
use Filament\Pages\Auth\PasswordReset\RequestPasswordReset;
|
||||
@@ -98,7 +99,7 @@ trait HasAuth
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function profile(?string $page): static
|
||||
public function profile(?string $page = EditProfile::class): static
|
||||
{
|
||||
$this->profilePage = $page;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user