49 lines
931 B
PHP
49 lines
931 B
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 function create() {
|
|
// Validate
|
|
$this->validate();
|
|
|
|
// Create the color
|
|
ColorModel::create([
|
|
$this->all()
|
|
]);
|
|
|
|
// Clear the form
|
|
$this->reset(['name', 'hex']);
|
|
}
|
|
|
|
public function delete(Color $color) {
|
|
@Auth::check();
|
|
$color->delete();
|
|
}
|
|
public function render()
|
|
{
|
|
return view('livewire.filament.color', [
|
|
'colors' => ColorModel::paginate(10)
|
|
]);
|
|
}
|
|
}
|