47 lines
882 B
PHP
47 lines
882 B
PHP
<?php
|
|
|
|
namespace App\Livewire\Color;
|
|
|
|
use Livewire\WithPagination;
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Component;
|
|
use Livewire\Attributes\title;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use App\Models\Color;
|
|
#[title('Colors')]
|
|
class Index extends Component
|
|
{
|
|
use WithPagination;
|
|
|
|
#[Validate('required')]
|
|
public $name = '';
|
|
|
|
#[Validate('required')]
|
|
public $hex = '';
|
|
|
|
public function create() {
|
|
// Validate
|
|
$this->validate();
|
|
|
|
// Create the color
|
|
Color::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.color.index', [
|
|
'colors' => Color::paginate(10)
|
|
]);
|
|
}
|
|
}
|