Skip to content

Instantly share code, notes, and snippets.

@dsturm
Last active November 5, 2021 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsturm/a92fab835a7a7ee7a1e8b5e765842d02 to your computer and use it in GitHub Desktop.
Save dsturm/a92fab835a7a7ee7a1e8b5e765842d02 to your computer and use it in GitHub Desktop.
Filament - User create
<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>
<?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