mirror of
https://github.com/filamentphp/filament.git
synced 2026-10-24 01:58:00 +08:00
Major refactor of fieldsets
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"/js/app.js": "/js/app.js?id=df43c48a98b1416bc88c",
|
||||
"/css/app.css": "/css/app.css?id=f5e2af426fd3f5a94981"
|
||||
"/css/app.css": "/css/app.css?id=4a7d1047b9caf5f93ae8"
|
||||
}
|
||||
|
||||
@@ -24,8 +24,4 @@ return [
|
||||
|
||||
'updated_at' => 'Last updated',
|
||||
|
||||
'direct_permissions' => 'Direct Permissions',
|
||||
|
||||
'permissions_from_roles' => 'Permissions are inherited from assigned roles. You may add direct permissions as needed.',
|
||||
|
||||
];
|
||||
@@ -38,6 +38,10 @@ return [
|
||||
|
||||
'delete_confirm' => 'Are you sure you want to delete the :name permission? This action cannot be undone.',
|
||||
|
||||
'direct_permissions' => 'Direct Permissions',
|
||||
|
||||
'permissions_from_roles' => 'Permissions are inherited from assigned roles. You may add direct permissions as needed.',
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
@@ -12,9 +12,15 @@ return [
|
||||
|
|
||||
*/
|
||||
|
||||
'settings' => 'Account settings',
|
||||
'name' => 'Name',
|
||||
|
||||
'account' => ':name\'s Account',
|
||||
'avatar' => 'Avatar',
|
||||
|
||||
'new_password' => 'New password',
|
||||
|
||||
'new_password_confirmation' => 'Confirm new password',
|
||||
|
||||
'settings' => 'Account settings',
|
||||
|
||||
'last_login_at' => 'Last login',
|
||||
|
||||
@@ -22,6 +28,10 @@ return [
|
||||
|
||||
'last_login_ip' => 'Last login IP',
|
||||
|
||||
'create' => 'New User',
|
||||
|
||||
'edit' => ':name\'s Account',
|
||||
|
||||
'delete' => 'Delete User',
|
||||
|
||||
'delete_confirm' => 'Are you sure you want to delete :name? This action cannot be undone.',
|
||||
@@ -2,31 +2,13 @@
|
||||
|
||||
@section('content')
|
||||
<div class="h-screen flex overflow-hidden" x-data="{ sidebarOpen: false }" @keydown.window.escape="sidebarOpen = false">
|
||||
{{-- Off-canvas menu for mobile --}}
|
||||
<div class="md:hidden">
|
||||
<div @click="sidebarOpen = false" class="fixed inset-0 z-30 bg-black opacity-0 pointer-events-none transition-opacity ease-linear duration-300" :class="{'opacity-75 pointer-events-auto': sidebarOpen, 'opacity-0 pointer-events-none': !sidebarOpen}"></div>
|
||||
<div class="fixed inset-y-0 left-0 flex flex-col z-40 max-w-xs w-full bg-gray-800 transform ease-in-out duration-300" :class="{'translate-x-0': sidebarOpen, '-translate-x-full': !sidebarOpen}">
|
||||
<div x-show="sidebarOpen" class="absolute top-3 right-0 -mr-16">
|
||||
<button @click="sidebarOpen = false" class="flex items-center h-12 w-12 transition ease-in-out duration-150 text-gray-500 dark:text-gray-400 hover:text-gray-900 dark-hover:text-gray-300 focus:outline-none">
|
||||
<x-heroicon-o-x class="h-6 w-6" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="h-0 flex-1 overflow-y-auto pt-5 pb-4">
|
||||
<div class="flex-shrink-0 flex items-center px-4">
|
||||
<x-filament-logo class="w-10 mr-3" />
|
||||
<h2 class="text-lg leading-5 font-medium text-gray-200">
|
||||
{{ config('app.name') }}
|
||||
</h2>
|
||||
</div>
|
||||
@include('filament::partials.nav', ['nav' => config('filament.nav.admin')])
|
||||
</div>
|
||||
<div class="flex-shrink-0 flex bg-gray-700 p-4">
|
||||
@include('filament::partials.user-actions')
|
||||
</div>
|
||||
<div @click="sidebarOpen = false" class="fixed z-30 md:hidden inset-0 bg-black opacity-0 pointer-events-none transition-opacity ease-linear duration-300" :class="{'opacity-75 pointer-events-auto': sidebarOpen, 'opacity-0 pointer-events-none': !sidebarOpen}"></div>
|
||||
<div class="fixed z-40 inset-y-0 left-0 w-64 bg-gray-800 flex flex-col transform ease-in-out duration-300 md:static md:flex-shrink-0" :class="{'translate-x-0': sidebarOpen, '-translate-x-full md:translate-x-0': !sidebarOpen}">
|
||||
<div x-show="sidebarOpen" class="absolute top-3 right-0 -mr-16 md:hidden">
|
||||
<button @click="sidebarOpen = false" class="flex items-center h-12 w-12 transition ease-in-out duration-150 text-gray-500 dark:text-gray-400 hover:text-gray-900 dark-hover:text-gray-300 focus:outline-none">
|
||||
<x-heroicon-o-x class="h-6 w-6" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{{-- Static sidebar for desktop --}}
|
||||
<div class="hidden w-64 bg-gray-800 md:flex-shrink-0 md:flex md:flex-col">
|
||||
<div class="flex-1 flex flex-col pt-5 pb-4 overflow-y-auto">
|
||||
<div class="flex items-center flex-shrink-0 px-4">
|
||||
<x-filament-logo class="w-10 mr-3" />
|
||||
|
||||
@@ -1,14 +1,27 @@
|
||||
@section('title', $title)
|
||||
|
||||
@section('actions')
|
||||
<button
|
||||
type="button"
|
||||
@click.prevent="$dispatch('filament-toggle-modal', { id: 'permission-create' })"
|
||||
class="btn btn-small btn-add"
|
||||
>
|
||||
<x-heroicon-o-plus class="h-3 w-3 mr-2" />
|
||||
{{ __('filament::permissions.permissions.create') }}
|
||||
</button>
|
||||
@can('create permissions')
|
||||
<button
|
||||
type="button"
|
||||
@click.prevent="$dispatch('filament-toggle-modal', { id: 'permission-create' })"
|
||||
class="btn btn-small btn-add"
|
||||
>
|
||||
<x-heroicon-o-plus class="h-3 w-3 mr-2" />
|
||||
{{ __('filament::permissions.permissions.create') }}
|
||||
</button>
|
||||
@push('footer')
|
||||
<x-filament-modal
|
||||
id="permission-create"
|
||||
:label="__('filament::permissions.permissions.create')"
|
||||
:esc-close="true"
|
||||
:click-outside="true"
|
||||
class="sm:max-w-xl"
|
||||
>
|
||||
create permission...
|
||||
</x-filament-modal>
|
||||
@endpush
|
||||
@endcan
|
||||
@endsection
|
||||
|
||||
<div>
|
||||
@@ -104,13 +117,14 @@
|
||||
<td @istrue ($permission->is_system, ' colspan="2"')>{{ $permission->updated_at->fromNow() }}</td>
|
||||
@isfalse ($permission->is_system)
|
||||
<td class="text-right">
|
||||
{{--
|
||||
<x-filament-dropdown dropdown-class="origin-top-right right-0 w-48">
|
||||
<x-slot name="button">
|
||||
<x-heroicon-o-dots-horizontal class="h-5 w-5" />
|
||||
</x-slot>
|
||||
<a href="{{ route('filament.admin.permissions.edit', ['id' => $permission->id]) }}">{{ __('Edit') }}</a>
|
||||
<button type="button" class="text-red-500">{{ __('Delete') }}</button>
|
||||
|
||||
</x-filament-dropdown>
|
||||
--}}
|
||||
</td>
|
||||
@endisfalse
|
||||
</tr>
|
||||
@@ -136,15 +150,3 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@push('footer')
|
||||
<x-filament-modal
|
||||
id="permission-create"
|
||||
:label="__('filament::permissions.permissions.create')"
|
||||
:esc-close="true"
|
||||
:click-outside="true"
|
||||
class="sm:max-w-xl"
|
||||
>
|
||||
create permission...
|
||||
</x-filament-modal>
|
||||
@endpush
|
||||
@@ -1,14 +1,27 @@
|
||||
@section('title', $title)
|
||||
|
||||
@section('actions')
|
||||
<button
|
||||
type="button"
|
||||
@click.prevent="$dispatch('filament-toggle-modal', { id: 'role-create' })"
|
||||
class="btn btn-small btn-add"
|
||||
>
|
||||
<x-heroicon-o-plus class="h-3 w-3 mr-2" />
|
||||
{{ __('filament::permissions.roles.create') }}
|
||||
</button>
|
||||
@can('create roles')
|
||||
<button
|
||||
type="button"
|
||||
@click.prevent="$dispatch('filament-toggle-modal', { id: 'role-create' })"
|
||||
class="btn btn-small btn-add"
|
||||
>
|
||||
<x-heroicon-o-plus class="h-3 w-3 mr-2" />
|
||||
{{ __('filament::permissions.roles.create') }}
|
||||
</button>
|
||||
@push('footer')
|
||||
<x-filament-modal
|
||||
id="role-create"
|
||||
:label="__('filament::permissions.roles.create')"
|
||||
:esc-close="true"
|
||||
:click-outside="true"
|
||||
class="sm:max-w-xl"
|
||||
>
|
||||
@livewire('filament::role-create')
|
||||
</x-filament-modal>
|
||||
@endpush
|
||||
@endcan
|
||||
@endsection
|
||||
|
||||
<div>
|
||||
@@ -71,31 +84,37 @@
|
||||
<x-slot name="button">
|
||||
<x-heroicon-o-dots-horizontal class="h-5 w-5" />
|
||||
</x-slot>
|
||||
<button @click.prevent="open = false; $dispatch('filament-toggle-modal', { id: 'role-edit-{{ $role->id }}' })" type="button">{{ __('Edit') }}</button>
|
||||
<button @click.prevent="open = false; $dispatch('filament-toggle-modal', { id: 'role-delete-{{ $role->id }}' })" type="button" class="text-red-500" type="button">{{ __('Delete') }}</button>
|
||||
@can('edit roles')
|
||||
<button @click.prevent="open = false; $dispatch('filament-toggle-modal', { id: 'role-edit-{{ $role->id }}' })" type="button">{{ __('Edit') }}</button>
|
||||
@push('footer')
|
||||
<x-filament-modal
|
||||
:id="'role-edit-'.$role->id"
|
||||
:label="__('filament::permissions.roles.edit')"
|
||||
:esc-close="true"
|
||||
:click-outside="true"
|
||||
class="sm:max-w-xl"
|
||||
>
|
||||
@livewire('filament::role-edit', ['role' => $role])
|
||||
</x-filament-modal>
|
||||
@endpush
|
||||
@endcan
|
||||
@can('delete roles')
|
||||
<button @click.prevent="open = false; $dispatch('filament-toggle-modal', { id: 'role-delete-{{ $role->id }}' })" type="button" class="text-red-500" type="button">{{ __('Delete') }}</button>
|
||||
@push('footer')
|
||||
<x-filament-modal
|
||||
:id="'role-delete-'.$role->id"
|
||||
:label="__('filament::permissions.roles.delete')"
|
||||
:esc-close="true"
|
||||
:click-outside="true"
|
||||
class="sm:max-w-md"
|
||||
>
|
||||
@livewire('filament::role-delete', ['role' => $role])
|
||||
</x-filament-modal>
|
||||
@endpush
|
||||
@endcan
|
||||
</x-filament-dropdown>
|
||||
</td>
|
||||
</tr>
|
||||
@push('footer')
|
||||
<x-filament-modal
|
||||
:id="'role-edit-'.$role->id"
|
||||
:label="__('filament::permissions.roles.edit')"
|
||||
:esc-close="true"
|
||||
:click-outside="true"
|
||||
class="sm:max-w-xl"
|
||||
>
|
||||
@livewire('filament::role-edit', ['role' => $role])
|
||||
</x-filament-modal>
|
||||
<x-filament-modal
|
||||
:id="'role-delete-'.$role->id"
|
||||
:label="__('filament::permissions.roles.delete')"
|
||||
:esc-close="true"
|
||||
:click-outside="true"
|
||||
class="sm:max-w-md"
|
||||
>
|
||||
@livewire('filament::role-delete', ['role' => $role])
|
||||
</x-filament-modal>
|
||||
@endpush
|
||||
@empty
|
||||
<tr>
|
||||
<td class="text-center" colspan="4">{{ __('No roles found.') }}</td>
|
||||
@@ -109,15 +128,3 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@push('footer')
|
||||
<x-filament-modal
|
||||
id="role-create"
|
||||
:label="__('filament::permissions.roles.create')"
|
||||
:esc-close="true"
|
||||
:click-outside="true"
|
||||
class="sm:max-w-xl"
|
||||
>
|
||||
@livewire('filament::role-create')
|
||||
</x-filament-modal>
|
||||
@endpush
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<form wire:submit.prevent="save">
|
||||
|
||||
<h2 class="text-xl lg:text-2xl font-semibold mb-4">{{ $title }}</h2>
|
||||
|
||||
<x-filament-tabs tab="account" :tabs="['account' => 'Account', 'permissions' => 'Permissions']">
|
||||
|
||||
<x-filament-tab id="account">
|
||||
|
||||
<x-filament-fields :fields="$fields" group="account" />
|
||||
|
||||
</x-filament-tab>
|
||||
|
||||
<x-filament-tab id="permissions">
|
||||
|
||||
<x-filament-fields :fields="$fields" group="permissions" />
|
||||
|
||||
</x-filament-tab>
|
||||
|
||||
<button type="submit" class="btn">{{ __('Save') }}</button>
|
||||
|
||||
</x-filament-tabs>
|
||||
|
||||
</form>
|
||||
@@ -1,16 +1,5 @@
|
||||
@section('title', $title)
|
||||
|
||||
@section('actions')
|
||||
<button
|
||||
type="button"
|
||||
@click.prevent="$dispatch('filament-toggle-modal', { id: 'user-delete' })"
|
||||
class="btn btn-small btn-danger"
|
||||
>
|
||||
<x-heroicon-o-trash class="h-3 w-3 mr-2" />
|
||||
{{ __('filament::user.delete') }}
|
||||
</button>
|
||||
@endsection
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-7 gap-4 lg:gap-8">
|
||||
|
||||
<form wire:submit.prevent="save" class="md:col-span-5">
|
||||
@@ -45,11 +34,11 @@
|
||||
<dt>{{ __('filament::fields.updated_at') }}</dt>
|
||||
<dd class="text-right">{{ $user->updated_at->fromNow() }}</dd>
|
||||
|
||||
<dt>{{ __('filament::user.last_login_at') }}</dt>
|
||||
<dd class="text-right">{{ $user->last_login_at ? $user->last_login_at->fromNow() : __('filament::user.last_login_never') }}</dd>
|
||||
<dt>{{ __('filament::users.last_login_at') }}</dt>
|
||||
<dd class="text-right">{{ $user->last_login_at ? $user->last_login_at->fromNow() : __('filament::users.last_login_never') }}</dd>
|
||||
|
||||
@if ($user->last_login_ip)
|
||||
<dt>{{ __('filament::user.last_login_ip') }}</dt>
|
||||
<dt>{{ __('filament::users.last_login_ip') }}</dt>
|
||||
<dd class="text-right">{{ $user->last_login_ip }}</dd>
|
||||
@endif
|
||||
|
||||
@@ -58,16 +47,3 @@
|
||||
</x-filament-well>
|
||||
|
||||
</div>
|
||||
|
||||
@push('footer')
|
||||
<x-filament-modal
|
||||
id="user-delete"
|
||||
:label="__('filament::user.delete')"
|
||||
:esc-close="true"
|
||||
:click-outside="true"
|
||||
class="sm:max-w-md"
|
||||
>
|
||||
{{ __('filament::user.delete') }}
|
||||
{{-- @livewire('filament::user-delete', ['user' => $user]) --}}
|
||||
</x-filament-modal>
|
||||
@endpush
|
||||
|
||||
@@ -4,12 +4,23 @@
|
||||
@can('create users')
|
||||
<button
|
||||
type="button"
|
||||
@click.prevent="$dispatch('filament-toggle-modal', { id: 'new-role' })"
|
||||
@click.prevent="$dispatch('filament-toggle-modal', { id: 'user-create' })"
|
||||
class="btn btn-small btn-add"
|
||||
>
|
||||
<x-heroicon-o-plus class="h-3 w-3 mr-2" />
|
||||
{{ __('New User') }}
|
||||
{{ __('filament::users.create') }}
|
||||
</button>
|
||||
@push('footer')
|
||||
<x-filament-modal
|
||||
id="user-create"
|
||||
:label="__('filament::permissions.permissions.create')"
|
||||
:esc-close="true"
|
||||
:click-outside="true"
|
||||
class="sm:max-w-3xl"
|
||||
>
|
||||
@livewire('filament::user-create')
|
||||
</x-filament-modal>
|
||||
@endpush
|
||||
@endcan
|
||||
@endsection
|
||||
|
||||
@@ -50,4 +61,4 @@
|
||||
</ul>
|
||||
|
||||
{{ $users->links('filament::partials.pagination') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<a
|
||||
href="{{ route('filament.admin.users.edit', ['id' => auth()->user()->id]) }}"
|
||||
>
|
||||
{{ __('filament::user.settings') }}
|
||||
{{ __('filament::users.settings') }}
|
||||
</a>
|
||||
<x-filament-form :action="route('filament.auth.logout')">
|
||||
<button type="submit">
|
||||
|
||||
@@ -58,7 +58,7 @@ class Checkbox extends Component
|
||||
* @param string $model
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($type = 'checkbox', $name, $label = null, $value = null, $model = null, $disabled = false)
|
||||
public function __construct($type = 'checkbox', $name, $label = null, $value, $model = null, $disabled = false)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->name = $name;
|
||||
|
||||
@@ -32,7 +32,7 @@ class Tab extends Component
|
||||
public function render()
|
||||
{
|
||||
return <<<'blade'
|
||||
<div role="tabpanel" id="{{ $id }}-tab" aria-labelledby="{{ $id }}" x-show="tab === '{{ $id }}'" :hidden="tab !== '{{ $id }}'">
|
||||
<div tabindex="0" role="tabpanel" id="{{ $id }}-tab" aria-labelledby="{{ $id }}" x-show="tab === '{{ $id }}'" :hidden="tab !== '{{ $id }}'">
|
||||
{{ $slot }}
|
||||
</div>
|
||||
blade;
|
||||
|
||||
@@ -21,7 +21,7 @@ class ForgotPasswordController extends Controller
|
||||
$title = __('Reset Password');
|
||||
|
||||
$fields = [
|
||||
Field::make(false, 'email', false)
|
||||
Field::make('email', false, 'email')
|
||||
->placeholder('E-mail Address')
|
||||
->input('email')
|
||||
->value('')
|
||||
|
||||
@@ -28,17 +28,16 @@ class LoginController extends Controller
|
||||
$title = __('filament::auth.login', ['name' => config('app.name')]);
|
||||
|
||||
$fields = [
|
||||
Field::make(false, 'email', false)
|
||||
->placeholder('E-mail Address')
|
||||
Field::make('email', false, 'email')
|
||||
->input('email')
|
||||
->value('')
|
||||
->placeholder('E-mail Address')
|
||||
->rules(['required']),
|
||||
Field::make(false, 'password', false)
|
||||
->placeholder('Password')
|
||||
Field::make('password', false, 'password')
|
||||
->input('password')
|
||||
->placeholder('Password')
|
||||
->rules(['required'])
|
||||
->help('<a href="'.route('filament.auth.password.forgot').'">'.__('Forgot Your Password?').'</a>'),
|
||||
Field::make('Remember me', 'remember')
|
||||
Field::make('remember', 'Remember me', 'remember')
|
||||
->checkbox()
|
||||
->value(1),
|
||||
];
|
||||
|
||||
@@ -42,16 +42,16 @@ class ResetPasswordController extends Controller
|
||||
$title = __('Reset Password');
|
||||
|
||||
$fields = [
|
||||
Field::make(false, 'email', false)
|
||||
Field::make('email', false, 'email')
|
||||
->placeholder('E-mail Address')
|
||||
->input('email')
|
||||
->value($request->email)
|
||||
->rules(['required']),
|
||||
Field::make(false, 'password', false)
|
||||
Field::make('password', false, 'password')
|
||||
->placeholder('Password')
|
||||
->input('password')
|
||||
->rules(['required', 'confirmed']),
|
||||
Field::make(false, 'password_confirmation', false)
|
||||
Field::make('password_confirmation', false, 'password_confirmation')
|
||||
->placeholder('Confirm Password')
|
||||
->input('password'),
|
||||
];
|
||||
|
||||
@@ -11,13 +11,13 @@ class RoleCreateFieldset implements Fieldset
|
||||
{
|
||||
public static function title(): string
|
||||
{
|
||||
return 'Create Role';
|
||||
return __('filament::permissions.roles.create');
|
||||
}
|
||||
|
||||
public static function fields($model = null): array
|
||||
public static function fields($model): array
|
||||
{
|
||||
return [
|
||||
Field::make('Name')
|
||||
Field::make('name')
|
||||
->input()
|
||||
->rules([
|
||||
'required',
|
||||
@@ -26,11 +26,11 @@ class RoleCreateFieldset implements Fieldset
|
||||
Rule::unique('roles', 'name'),
|
||||
])
|
||||
->group('info'),
|
||||
Field::make('Description')
|
||||
Field::make('description')
|
||||
->textarea()
|
||||
->rules(['string', 'nullable'])
|
||||
->group('info'),
|
||||
Field::make('filament::admin.permissions', 'permissions')
|
||||
Field::make('permissions')
|
||||
->checkboxes(Permission::orderBy('name')
|
||||
->pluck('id', 'name')
|
||||
->all())
|
||||
|
||||
@@ -11,13 +11,13 @@ class RoleEditFieldset implements Fieldset
|
||||
{
|
||||
public static function title(): string
|
||||
{
|
||||
return 'Edit Role';
|
||||
return __('filament::permissions.roles.edit');
|
||||
}
|
||||
|
||||
public static function fields($model): array
|
||||
{
|
||||
return [
|
||||
Field::make('Name')
|
||||
Field::make('name')
|
||||
->input()
|
||||
->rules([
|
||||
'required',
|
||||
@@ -26,11 +26,11 @@ class RoleEditFieldset implements Fieldset
|
||||
Rule::unique('roles', 'name')->ignore($model->id),
|
||||
])
|
||||
->group('info'),
|
||||
Field::make('Description')
|
||||
Field::make('description')
|
||||
->textarea()
|
||||
->rules(['string', 'nullable'])
|
||||
->group('info'),
|
||||
Field::make('filament::admin.permissions', 'permissions')
|
||||
Field::make('permissions')
|
||||
->checkboxes(Permission::orderBy('name')
|
||||
->pluck('id', 'name')
|
||||
->all())
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Http\Fieldsets;
|
||||
|
||||
use Filament\Contracts\Fieldset;
|
||||
use Filament\Support\Fields\Field;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Filament\Models\Role;
|
||||
use Filament\Models\Permission;
|
||||
|
||||
class UserCreateFieldset implements Fieldset
|
||||
{
|
||||
public static function title(): string
|
||||
{
|
||||
return __('filament::users.create');
|
||||
}
|
||||
|
||||
public static function fields($model): array
|
||||
{
|
||||
return [
|
||||
Field::make('name')
|
||||
->input()
|
||||
->rules(['required', 'string', 'max:255'])
|
||||
->group('account'),
|
||||
Field::make('email')
|
||||
->input('email')
|
||||
->rules([
|
||||
'required',
|
||||
'string',
|
||||
'email',
|
||||
'max:255',
|
||||
Rule::unique('users', 'email'),
|
||||
])
|
||||
->group('account'),
|
||||
Field::make('password')
|
||||
->input('password')
|
||||
->autocomplete('new-password')
|
||||
->rules(['required', 'min:8', 'confirmed'])
|
||||
->group('account'),
|
||||
Field::make('password_confirmation', false)
|
||||
->placeholder('Confirm Password')
|
||||
->input('password')
|
||||
->autocomplete('new-password')
|
||||
->rules('required')
|
||||
->group('account'),
|
||||
Field::make('is_super_admin')
|
||||
->checkbox()
|
||||
->default(false)
|
||||
->help(__('filament::permissions.super_admin_info'))
|
||||
->group('permissions')
|
||||
->disabled(!auth()->user()->is_super_admin)
|
||||
->group('permissions'),
|
||||
Field::make('roles')
|
||||
->checkboxes(Role::orderBy('name')
|
||||
->pluck('id', 'name')
|
||||
->all())
|
||||
->rules([Rule::exists('roles', 'id')])
|
||||
->disabled(!auth()->user()->can('edit user roles'))
|
||||
->group('permissions'),
|
||||
Field::make('direct_permissions')
|
||||
->checkboxes(Permission::orderBy('name')
|
||||
->pluck('id', 'name')
|
||||
->all())
|
||||
->rules([Rule::exists('permissions', 'id')])
|
||||
->help(__('filament::permissions.permissions.permissions_from_roles'))
|
||||
->disabled(!auth()->user()->can('edit user permissions'))
|
||||
->group('permissions'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function rulesIgnoreRealtime(): array
|
||||
{
|
||||
return ['confirmed'];
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,12 @@ class UserEditFieldset implements Fieldset
|
||||
public static function fields($model): array
|
||||
{
|
||||
return [
|
||||
Field::make('Name')
|
||||
Field::make('name')
|
||||
->input()
|
||||
->rules(['required', 'string', 'max:255'])
|
||||
->class('md:col-span-2')
|
||||
->group('account'),
|
||||
Field::make('Email')
|
||||
Field::make('email', 'E-mail Address')
|
||||
->input('email')
|
||||
->rules([
|
||||
'required',
|
||||
@@ -34,7 +34,7 @@ class UserEditFieldset implements Fieldset
|
||||
])
|
||||
->class('md:col-span-2')
|
||||
->group('account'),
|
||||
Field::make('Avatar')
|
||||
Field::make('avatar')
|
||||
->rules('array')
|
||||
->file()
|
||||
->fileRules('image')
|
||||
@@ -42,23 +42,23 @@ class UserEditFieldset implements Fieldset
|
||||
'image' => __('The Avatar must be a valid image.'),
|
||||
])
|
||||
->group('account'),
|
||||
Field::make('New Password', 'password')
|
||||
Field::make('password', 'New password')
|
||||
->input('password')
|
||||
->autocomplete('new-password')
|
||||
->rules(['sometimes', 'confirmed'])
|
||||
->rules(['nullable', 'min:8', 'confirmed'])
|
||||
->help('Leave blank to keep current password.')
|
||||
->group('account'),
|
||||
Field::make(false, 'password_confirmation')
|
||||
Field::make('password_confirmation', false)
|
||||
->placeholder('Confirm New Password')
|
||||
->input('password')
|
||||
->autocomplete('new-password')
|
||||
->group('account'),
|
||||
Field::make('filament::permissions.super_admin', 'is_super_admin')
|
||||
Field::make('is_super_admin')
|
||||
->checkbox()
|
||||
->help(__('filament::permissions.super_admin_info'))
|
||||
->group('permissions')
|
||||
->disabled(!auth()->user()->is_super_admin),
|
||||
Field::make('filament::admin.roles', 'roles')
|
||||
Field::make('roles')
|
||||
->checkboxes(Role::orderBy('name')
|
||||
->pluck('id', 'name')
|
||||
->all())
|
||||
@@ -68,7 +68,7 @@ class UserEditFieldset implements Fieldset
|
||||
->rules([Rule::exists('roles', 'id')])
|
||||
->group('permissions')
|
||||
->disabled(!auth()->user()->can('edit user roles')),
|
||||
Field::make('filament::fields.direct_permissions', 'direct_permissions')
|
||||
Field::make('direct_permissions')
|
||||
->checkboxes(Permission::orderBy('name')
|
||||
->pluck('id', 'name')
|
||||
->all())
|
||||
@@ -76,7 +76,7 @@ class UserEditFieldset implements Fieldset
|
||||
->pluck('id')
|
||||
->all()))
|
||||
->rules([Rule::exists('permissions', 'id')])
|
||||
->help(__('filament::fields.permissions_from_roles'))
|
||||
->help(__('filament::permissions.permissions.permissions_from_roles'))
|
||||
->group('permissions')
|
||||
->disabled(!auth()->user()->can('edit user permissions')),
|
||||
];
|
||||
|
||||
@@ -15,12 +15,6 @@ class RoleCreate extends FormComponent
|
||||
$this->setFormProperties();
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->authorize('create', Role::class);
|
||||
$this->submit();
|
||||
}
|
||||
|
||||
public function success()
|
||||
{
|
||||
$input = collect($this->form_data);
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Http\Livewire;
|
||||
|
||||
use Filament\Support\Livewire\FormComponent;
|
||||
use Filament\Contracts\User as UserContract;
|
||||
|
||||
class UserCreate extends FormComponent
|
||||
{
|
||||
public function mount()
|
||||
{
|
||||
$this->authorize('create', app(UserContract::class));
|
||||
|
||||
$this->setFieldset();
|
||||
$this->setFormProperties();
|
||||
}
|
||||
|
||||
public function success()
|
||||
{
|
||||
$input = collect($this->form_data);
|
||||
|
||||
$user = app(UserContract::class)::create($input->all());
|
||||
|
||||
session()->flash('notification', [
|
||||
'type' => 'success',
|
||||
'message' => __('filament::notifications.created', ['item' => $user->name]),
|
||||
]);
|
||||
|
||||
return redirect()->route('filament.admin.users.index');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('filament::livewire.users.create', [
|
||||
'title' => __('filament::users.create'),
|
||||
'fields' => $this->fields(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -45,33 +45,12 @@ class UserEdit extends FormComponent
|
||||
]);
|
||||
|
||||
$this->emit('filament.userUpdated', $this->model->id);
|
||||
|
||||
$this->updateAuthUser();
|
||||
}
|
||||
|
||||
public function saveField($field_name)
|
||||
{
|
||||
$this->model->$field_name = $this->form_data[$field_name];
|
||||
$this->model->save();
|
||||
$this->emit('filament.notification.notify', [
|
||||
'type' => 'success',
|
||||
'message' => __('filament::notifications.updated', ['item' => $field_name]),
|
||||
]);
|
||||
|
||||
$this->updateAuthUser();
|
||||
}
|
||||
|
||||
protected function updateAuthUser()
|
||||
{
|
||||
if (auth()->user()->id === $this->model->id) {
|
||||
$this->emit('filament.userUpdated');
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('filament::livewire.users.edit', [
|
||||
'title' => __('filament::user.account', ['name' => $this->model->name]),
|
||||
'title' => __('filament::users.edit', ['name' => $this->model->name]),
|
||||
'fields' => $this->fields(),
|
||||
'user' => $this->model,
|
||||
]);
|
||||
|
||||
@@ -34,11 +34,6 @@ class Authenticate extends Middleware
|
||||
protected function redirectTo($request)
|
||||
{
|
||||
if (! $request->expectsJson()) {
|
||||
session()->flash('notification', [
|
||||
'type' => 'warning',
|
||||
'message' => __('filament::auth.sign_in'),
|
||||
]);
|
||||
|
||||
return route('filament.auth.login');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class ResetPassword extends Notification
|
||||
$url = url(config('app.url').route('filament.auth.password.reset', [
|
||||
'token' => $this->token,
|
||||
'email' => $notifiable->getEmailForPasswordReset(),
|
||||
], false));
|
||||
]));
|
||||
}
|
||||
|
||||
return (new MailMessage)
|
||||
|
||||
@@ -6,21 +6,29 @@ use Illuminate\Support\Str;
|
||||
|
||||
class Field extends BaseField
|
||||
{
|
||||
protected $id;
|
||||
protected $name;
|
||||
protected $label;
|
||||
protected $key;
|
||||
protected $id;
|
||||
|
||||
public function __construct($label, $name, $key_prefix = true)
|
||||
public function __construct($name, $label = null, $key = null)
|
||||
{
|
||||
$this->name = $name ?? Str::snake(Str::lower($label));
|
||||
$this->label = __($label);
|
||||
$this->key = $key_prefix ? 'form_data.'.$this->name : $this->name;
|
||||
$this->id = Str::uuid();
|
||||
$this->name = $name;
|
||||
$this->label = is_null($label) ? $this->formatLabel($name) : $label;
|
||||
$this->key = $key ?? 'form_data.'.$this->name;
|
||||
$this->id = Str::slug($this->key);
|
||||
}
|
||||
|
||||
public static function make($label, $name = null, $key_prefix = true)
|
||||
public static function make($name, $label = null, $key = null)
|
||||
{
|
||||
return new static($label, $name, $key_prefix);
|
||||
return new static($name, $label, $key);
|
||||
}
|
||||
|
||||
protected function formatLabel($value)
|
||||
{
|
||||
return Str::of($value)
|
||||
->replaceMatches('/[\-_]/', ' ')
|
||||
->title()
|
||||
->__toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ trait FollowsRules
|
||||
$field_rules = is_array($field->rules) ? $field->rules : explode('|', $field->rules);
|
||||
|
||||
if ($rules_ignore) {
|
||||
$field_rules = array_udiff($field_rules, $rules_ignore, function ($a, $b) {
|
||||
return $a != $b;
|
||||
});
|
||||
$field_rules = collect($field_rules)->filter(function ($value, $key) use ($rules_ignore) {
|
||||
return !in_array($value, $rules_ignore);
|
||||
})->all();
|
||||
}
|
||||
|
||||
|
||||
return $field_rules;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,11 @@ trait HasFields
|
||||
|
||||
public function saveField($field_name)
|
||||
{
|
||||
//
|
||||
$this->model->$field_name = $this->form_data[$field_name];
|
||||
$this->model->save();
|
||||
$this->emit('filament.notification.notify', [
|
||||
'type' => 'success',
|
||||
'message' => __('filament::notifications.updated', ['item' => $field_name]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user