Adding RaidForm livewire component
This commit is contained in:
parent
4a7c2dd66c
commit
1e624a2f6c
2 changed files with 95 additions and 0 deletions
78
app/Http/Livewire/Form/RaidForm.php
Normal file
78
app/Http/Livewire/Form/RaidForm.php
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Form;
|
||||
|
||||
use App\Models\Raid;
|
||||
|
||||
use App\Http\Livewire\Traits\Alert;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class RaidForm extends Component
|
||||
{
|
||||
use Alert;
|
||||
|
||||
/**
|
||||
* The raid record
|
||||
*/
|
||||
public $raid;
|
||||
|
||||
/**
|
||||
* True if the record already exists in the database.
|
||||
*/
|
||||
public bool $exist;
|
||||
|
||||
public function mount(Raid $raid)
|
||||
{
|
||||
$this->raid = $raid;
|
||||
$this->exist = $raid->exists;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation rules
|
||||
*/
|
||||
protected function rules()
|
||||
{
|
||||
return [
|
||||
'raid.name' => 'required|string|min:2|max:20',
|
||||
];
|
||||
}
|
||||
|
||||
public function updated($property, $value)
|
||||
{
|
||||
$this->validateOnly($property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this card has not been stored in the database.
|
||||
*/
|
||||
public function isNew() : bool
|
||||
{
|
||||
return !$this->exist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the form, create/update card.
|
||||
*/
|
||||
public function submit()
|
||||
{
|
||||
$this->validate();
|
||||
$this->raid->save();
|
||||
|
||||
if ($this->isNew()) {
|
||||
session()->flash('info', 'Raid was successfully created.');
|
||||
return redirect()->route('admin.character.index');
|
||||
}
|
||||
|
||||
$this->info('Raid was successfully updated.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the setup page
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('form.raid')
|
||||
->layout('layouts.admin');
|
||||
}
|
||||
}
|
||||
17
resources/views/form/raid.blade.php
Normal file
17
resources/views/form/raid.blade.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
<div class="space-y-4">
|
||||
|
||||
<x-header>{{ __(($this->isNew() ? 'Create' : 'Edit') . ' raid') }}</x-header>
|
||||
|
||||
<form class="space-y-4" wire:submit.prevent="submit">
|
||||
|
||||
<div>
|
||||
<x-ignite-label for="raid.name">{{ __('Name') }}</x-ignite-label>
|
||||
<x-ignite-input name="raid.name" wire:model="raid.name" />
|
||||
</div>
|
||||
|
||||
<x-button type="info">{{ __('Save') }}</x-button>
|
||||
<x-button href="{{ route('admin.raid.index') }}" type="warning">{{ __('Back') }}</x-button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
Reference in a new issue