37 lines
751 B
PHP
37 lines
751 B
PHP
<?php
|
|
|
|
namespace App\Livewire\Modals;
|
|
|
|
use App\Models\Room;
|
|
use LivewireUI\Modal\ModalComponent;
|
|
|
|
class CreateRoom extends ModalComponent
|
|
{
|
|
public string $name = '';
|
|
|
|
public string $icon = 'rooms';
|
|
|
|
public function save()
|
|
{
|
|
$this->validate([
|
|
'name' => 'required|string|max:100',
|
|
'icon' => 'required|string|in:'.implode(',', Room::ICON_CHOICES),
|
|
]);
|
|
|
|
Room::create([
|
|
'name' => $this->name,
|
|
'icon' => $this->icon,
|
|
'sort' => (int) (Room::max('sort') ?? 0) + 1,
|
|
]);
|
|
|
|
$this->closeModal();
|
|
|
|
return redirect()->route('rooms.index');
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.modals.create-room');
|
|
}
|
|
}
|