Refactored Color Livewire components, added CreateColor, EditColor, and ShowColor components. Updated views, navigation, and Tailwind color schemes. Adjusted database migrations for consistency.

This commit is contained in:
2025-12-14 01:39:16 +01:00
parent 7e79d1d034
commit ac812ed142
32 changed files with 496 additions and 353 deletions
+9 -88
View File
@@ -3,10 +3,7 @@
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;
@@ -15,104 +12,28 @@ 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 create(){
return $this->redirectRoute('color.create', navigate: true);
}
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 edit($id){
return $this->redirectRoute('color.edit', $id, navigate: true);
}
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 show($id){
return $this->redirectRoute('color.show', $id, navigate: true);
}
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 delete($id){
ColorModel::destroy($id);
}
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)
'colors' => ColorModel::search('name', $this->search)->paginate(10)
]);
}
}
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\Livewire\Color;
use App\Models\Color as Model;
use Livewire\Attributes\title;
use Livewire\Component;
#[title('Colors')]
class CreateColor extends Component
{
public Model $color ;
public string $name = '';
public string $hex = '';
public function save(){
$this->validate([
'name' => ['required', 'string', 'max:255'],
'hex' => ['required', 'string', 'size:6', 'regex:/^[0-9A-F]{6}$/'],
]);
$color = new Model();
$color->name = $this->name;
$color->hex = $this->hex;
$color->save();
return $this->redirectRoute('color.show', $color->id, navigate: true);
}
public function cancel(){
return $this->redirectRoute('color.index', navigate: true);
}
public function render()
{
return view('livewire.color.create', [
]);
}
}
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace App\Livewire\Color;
use App\Models\Color as Model;
use Livewire\Attributes\title;
use Livewire\Attributes\Validate;
use Livewire\Component;
#[title('Colors')]
class EditColor extends Component
{
public Model $color;
public string $name = '';
public string $hex = '';
public function mount(Model $color){
$this->color = $color;
$this->name = $color->name;
$this->hex = $color->hex;
}
#[Validate('required')]
public function save(){
$this->validate([
'name' => ['required', 'string', 'max:255'],
'hex' => ['required', 'string', 'size:6', 'regex:/^[0-9A-F]{6}$/'],
]);
$this->color->update([
'name' => $this->name,
'hex' => $this->hex,
]);
return $this->redirectRoute('color.show', $this->color->id, navigate: true);
}
public function cancel(){
return $this->redirectRoute('color.index', navigate: true);
}
public function render()
{
return view('livewire.color.edit', [
]);
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace App\Livewire\Color;
use App\Models\Color as Model;
use Livewire\Attributes\title;
use Livewire\Component;
#[title('Colors')]
class ShowColor extends Component
{
public Model $color;
public function mount(Model $color){
$this->color = $color;
}
public function edit($id){
return $this->redirectRoute('color.edit', $id, navigate: true);
}
public function back(){
return $this->redirectRoute('color.index', navigate: true);
}
public function render()
{
return view('livewire.color.show', [
]);
}
}
+1 -1
View File
@@ -12,7 +12,7 @@ class Dashboard extends Component
public function render()
{
return view('livewire.dashboard', [
'manufacturer' => Manufacturer::all()->sortBy('filament_count')->reverse()
'manufacturers' => Manufacturer::all()->sortBy('filament_count')->reverse()
]);
}
}
+2 -2
View File
@@ -34,11 +34,11 @@ class CreateType extends Component
$type->description = $this->description;
$type->save();
return redirect()->route('type.index');
return $this->redirectRoute('type.show', $type->id, navigate: true);
}
public function cancel(){
return redirect()->route('type.index');
return $this->redirectRoute('type.index', navigate: true);
}
public function render()
{
+23 -12
View File
@@ -2,8 +2,7 @@
namespace App\Livewire\Type;
use App\Models\FilamentType;
use Illuminate\Support\Facades\Auth;
use App\Models\FilamentType as Model;
use Livewire\Attributes\title;
use Livewire\Attributes\Validate;
use Livewire\Component;
@@ -11,29 +10,41 @@ use Livewire\Component;
#[title('Types')]
class EditType extends Component
{
public FilamentType $type;
public Model $type;
public string $name = '';
public string $description = '';
public function mount(Model $type)
{
$this->type = $type;
$this->name = $type->name;
$this->description = $type->description;
}
// Validation
#[Validate('required')]
public function save() {
public function save()
{
$this->validate([
'type.name' => ['required', 'string', 'max:255'],
'type.description' => ['nullable', 'string'],
]);
$this->type->save();
$this->type->update([
'name' => $this->name,
'description' => $this->description,
]);
return redirect()->route('type.show', $this->type->id );
return $this->redirectRoute('type.show', $this->type->id, navigate: true);
}
public function cancel(){
return redirect()->route('type.index');
public function cancel()
{
return $this->redirectRoute('type.index', navigate: true);
}
public function mount(FilamentType $type){
$this->type = $type;
}
public function render()
{
return view('livewire.type.edit', [
+2 -2
View File
@@ -16,11 +16,11 @@ class ShowType extends Component
public FilamentType $type;
public function back(){
return redirect()->route('type.index');
return $this->redirectRoute('type.index', navigate: true);
}
public function edit($id){
return redirect()->route('type.edit', $id);
return $this->redirectRoute('type.edit', $id, navigate: true);
}
public function mount(FilamentType $type){
+11 -7
View File
@@ -20,15 +20,19 @@ class Type extends Component
// Validation
#[Validate('required')]
public function create() {
@Auth::check();
return redirect()->route('type.create');
public function create()
{
return $this->redirectRoute('type.create', navigate: true);
}
public function edit($id){
return redirect()->route('type.edit', $id);
public function edit($id)
{
return $this->redirectRoute('type.edit', $id, navigate: true);
}
public function show($id){
return redirect()->route('type.show', $id);
public function show($id)
{
return $this->redirectRoute('type.show', $id, navigate: true);
}
public function delete($id){
@Auth::check();
-12
View File
@@ -15,17 +15,5 @@ class Color extends Model
'hex'
];
// Color has many filaments
public function filaments()
{
return $this->hasMany(Filament::class);
}
// Color has many filament type
public function filamentTypes()
{
return $this->hasMany(FilamentType::class);
}
}