59 lines
1.1 KiB
PHP
59 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Filament;
|
|
|
|
use Livewire\WithPagination;
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Component;
|
|
use Livewire\Attributes\title;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use App\Models\Color as ColorModel;
|
|
|
|
#[title('Colors')]
|
|
class Color extends Component
|
|
{
|
|
use WithPagination;
|
|
|
|
// Validation
|
|
#[Validate('required')]
|
|
public $name = '';
|
|
|
|
#[Validate('required')]
|
|
public $hex = '';
|
|
|
|
public $createModal = false;
|
|
|
|
public function create() {
|
|
@Auth::check();
|
|
|
|
|
|
// Validate
|
|
$this->validate();
|
|
|
|
$color = new ColorModel();
|
|
$color->name = $this->name;
|
|
$color->hex = $this->hex;
|
|
$color->save();
|
|
|
|
session()->flash('status', 'Color successfully created.');
|
|
|
|
// Clear the form
|
|
$this->reset(['name', 'hex']);
|
|
|
|
// Close the modal
|
|
$this->createModal = false;
|
|
}
|
|
|
|
public function delete(Color $color) {
|
|
@Auth::check();
|
|
$color->delete();
|
|
}
|
|
public function render()
|
|
{
|
|
return view('livewire.filament.color', [
|
|
'colors' => ColorModel::paginate(10)
|
|
]);
|
|
}
|
|
}
|