120 lines
2.6 KiB
PHP
120 lines
2.6 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 Flux\Flux;
|
|
|
|
use App\Models\Color as ColorModel;
|
|
|
|
#[title('Colors')]
|
|
class Color extends Component
|
|
{
|
|
use WithPagination;
|
|
|
|
// Validation
|
|
#[Validate('required')]
|
|
public $name = '';
|
|
|
|
#[Validate('required')]
|
|
public $hex = '';
|
|
|
|
public $search ='';
|
|
|
|
// Edit Modal + Query
|
|
public $editquery = '';
|
|
|
|
public $editid = '';
|
|
public $deleteid = '';
|
|
|
|
|
|
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
|
|
Flux::modal('createModal')->close();
|
|
}
|
|
|
|
public function edit($colorid) {
|
|
@Auth::check();
|
|
|
|
$editid = $colorid;
|
|
$this->editid = $editid;
|
|
|
|
$color =ColorModel::findOrFail($editid);
|
|
|
|
$this->name = $color->name;
|
|
$this->hex = $color->hex;
|
|
|
|
Flux::modal('editModal')->show();
|
|
}
|
|
|
|
public function save($editid) {
|
|
@Auth::check();
|
|
|
|
$color = ColorModel::findOrFail($editid);
|
|
$color->name = $this->name;
|
|
$color->hex = $this->hex;
|
|
$color->save();
|
|
|
|
session()->flash('status', 'Color successfully updated.');
|
|
|
|
Flux::modal('editModal')->close();
|
|
}
|
|
|
|
public function deleteModal($colorid) {
|
|
@Auth::check();
|
|
|
|
$deleteid = $colorid;
|
|
$this->deleteid = $deleteid;
|
|
|
|
$color = ColorModel::findOrFail($colorid);
|
|
$this->name = $color->name;
|
|
$this->hex = $color->hex;
|
|
|
|
Flux::modal('deleteModal')->show();
|
|
}
|
|
public function delete($deleteid) {
|
|
@Auth::check();
|
|
|
|
$color = ColorModel::findOrFail($deleteid)->delete();
|
|
|
|
$this->deleteid = $deleteid;
|
|
Flux::modal('deleteModal')->close();
|
|
|
|
// Clear the form
|
|
$this->reset(['name', 'hex', 'deleteid']);
|
|
|
|
session()->flash('status', 'Color successfully deleted.');
|
|
}
|
|
|
|
public function cancel() {
|
|
$this->reset(['name', 'hex', 'deleteid']);
|
|
Flux::modals()->close();
|
|
}
|
|
public function render()
|
|
{
|
|
return view('livewire.filament.color', [
|
|
'colors' => ColorModel::search('name', $this->search)->paginate(20)
|
|
]);
|
|
}
|
|
}
|