Renamed and reorganized Livewire components, namespaces, and views for improved file structure and clarity. Introduced filaments.show and filaments.edit routes. Updated database migrations and navigation routes accordingly. Upgraded dependencies in composer.
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Color;
|
||||
|
||||
use App\Models\Color as ColorModel;
|
||||
use Flux\Flux;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Attributes\title;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
#[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.color.index', [
|
||||
'colors' => ColorModel::search('name', $this->search)->paginate(20)
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user