Add Spareparts module with CRUD functionality and UI components.

This commit is contained in:
2026-01-24 10:15:45 +01:00
parent af0cf8bed9
commit 563b0e750e
18 changed files with 502 additions and 9 deletions
@@ -0,0 +1,46 @@
<?php
namespace App\Livewire\Sparepart;
use Livewire\Attributes\Validate;
use Livewire\Component;
use App\Models\Sparepart as Model;
use Livewire\Attributes\title;
#[title('Create Sparepart')]
class CreateSparepart extends Component
{
public Model $sparepart ;
public string $name = '';
public string $description = '';
public int $manufacturer_id = 0;
#[Validate('required')]
public function save(){
$this->validate([
'name' => ['required', 'string', 'max:255'],
'description' => ['nullable', 'string', 'max:255'],
'manufacturer_id' => ['required', 'integer'],
]);
$sparepart = new Model();
$sparepart->name = $this->name;
$sparepart->description = $this->description;
$sparepart->manufacturer_id = $this->manufacturer_id;
$sparepart->save();
return $this->redirectRoute('spareparts.show', $sparepart->id, navigate: true);
}
public function cancel(){
return $this->redirectRoute('spareparts.index', navigate: true);
}
public function render()
{
return view('livewire.sparepart.create', [
]);
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php
namespace App\Livewire\Sparepart;
use Livewire\Attributes\Validate;
use Livewire\Component;
use App\Models\Sparepart as Model;
use Livewire\Attributes\title;
#[title('Edit Sparepart')]
class EditSparepart extends Component
{
public Model $sparepart ;
public string $name = '';
public string $description = '';
public int $manufacturer_id = 0;
#[Validate('required')]
public function save(){
$this->validate([
'name' => ['required', 'string', 'max:255'],
'description' => ['nullable', 'string', 'max:255'],
'manufacturer_id' => ['required', 'integer'],
]);
$this->sparepart->update([
'name' => $this->name,
'description' => $this->description,
'manufacturer_id' => $this->manufacturer_id
]);
return $this->redirectRoute('spareparts.show', $this->sparepart->id, navigate: true);
}
public function cancel(){
return $this->redirectRoute('spareparts.index', navigate: true);
}
public function mount(Model $sparepart){
$this->filament = $sparepart;
$this->name = $sparepart->name;
$this->description = $sparepart->description;
$this->manufacturer_id = $sparepart->manufacturer_id;
}
public function render()
{
return view('livewire.sparepart.create', [
]);
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace App\Livewire\Sparepart;
use Livewire\Component;
use App\Models\Sparepart as Model;
use Livewire\Attributes\title;
#[title('Show Filament')]
class ShowSparepart extends Component
{
public Model $sparepart ;
public function back(){
return redirect()->route('spareparts.index');
}
public function edit($id){
return redirect()->route('spareparts.edit', $id);
}
public function render()
{
return view('livewire.sparepart.show', [
]);
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace App\Livewire\Sparepart;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use App\Models\Sparepart as Model;
use App\Models\Manufacturer as Manufacturer;
use Livewire\WithPagination;
use Livewire\Attributes\title;
#[title('Filaments')]
class Sparepart extends Component
{
use WithPagination;
public Model $sparepart ;
public $search = '';
public function create(){
return $this->redirectRoute('spareparts.create', navigate: true);
}
public function show($id){
return $this->redirectRoute('spareparts.show', $id);
}
public function edit($id){
return $this->redirectRoute('spareparts.edit', $id);
}
public function delete($id){
@Auth::check();
Model::destroy($id);
}
public function render()
{
return view('livewire.sparepart.index', [
'spareparts' => Model::search('name', $this->search)->paginate(25)
]);
}
}
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Sparepart extends Model
{
// Sparepart Model
protected $table = 'spareparts';
protected $primaryKey = 'id';
protected $fillable = [
'name',
'description',
];
public function manufacturer()
{
return $this->belongsTo(Manufacturer::class);
}
}