Last active
November 5, 2021 15:06
-
-
Save dsturm/a92fab835a7a7ee7a1e8b5e765842d02 to your computer and use it in GitHub Desktop.
Filament - User create
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
{{ $this->form }} | |
<div class="flex mt-4"> | |
<x-jet-button wire:click="create"> | |
{{ __('Create') }} | |
</x-jet-button> | |
<x-jet-action-message class="ml-3" on="saved"> | |
{{ __('Saved.') }} | |
</x-jet-action-message> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Livewire\Users; | |
use App\Models\User; | |
use Filament\Forms\Components\TextInput; | |
use Filament\Forms\Concerns\InteractsWithForms; | |
use Filament\Forms\Contracts\HasForms; | |
use Livewire\Component; | |
class Create extends Component implements HasForms | |
{ | |
use InteractsWithForms; | |
public User $user; | |
public $name; | |
public $email; | |
public function mount(): void | |
{ | |
$this->form->fill(); | |
} | |
protected function getFormSchema(): array | |
{ | |
return [ | |
'name' => TextInput::make('name') | |
->required(), | |
'email' => TextInput::make('email') | |
->email() | |
->required(), | |
]; | |
} | |
protected function getFormModel(): string | |
{ | |
return User::class; | |
} | |
public function create(): void | |
{ | |
$user = User::create($this->form->getState()); | |
$this->form->model($user)->saveRelationships(); | |
} | |
public function render() | |
{ | |
return view('livewire.users.create'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment