created Filament View with Livewire
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Filament;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\Filament as Model;
|
||||
use App\Models\Color as Color;
|
||||
use App\Models\FilamentType as Type;
|
||||
use App\Models\Manufacturer as Manufacturer;
|
||||
use Livewire\WithPagination;
|
||||
use Livewire\Attributes\title;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Flux\Flux;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
#[title('Filaments')]
|
||||
class Filament extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
#[Validate('required')]
|
||||
public $name = '';
|
||||
public $description = '';
|
||||
public $diameter = '1.75';
|
||||
public $color_id = '';
|
||||
public $type_id = '';
|
||||
public $manufacturer_id = '';
|
||||
public $weight = '1000';
|
||||
public $price = '0';
|
||||
public $stock = '0';
|
||||
|
||||
public $search = '';
|
||||
|
||||
public $editid = '';
|
||||
public $deleteid = '';
|
||||
|
||||
public function create() {
|
||||
@Auth::check();
|
||||
|
||||
// Validate
|
||||
$this->validate();
|
||||
|
||||
$filament = new Model();
|
||||
$filament->name = $this->name;
|
||||
$filament->description = $this->description;
|
||||
$filament->diameter = $this->diameter;
|
||||
$filament->color_id = Color::Find($this->color_id);
|
||||
$filament->filament_type_id = Type::Find($this->type_id);
|
||||
$filament->manufacturer_id = Manufacturer::Find($this->manufacturer_id);
|
||||
$filament->weight = $this->weight;
|
||||
$filament->price = $this->price;
|
||||
$filament->stock = $this->stock;
|
||||
$filament->save();
|
||||
|
||||
// Clear the form
|
||||
$this->resetInputFields();
|
||||
|
||||
// Close the modal
|
||||
Flux::modal('createModal')->close();
|
||||
}
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.filament.filament', [
|
||||
'filaments' => Model::search('name', $this->search)->paginate(10),
|
||||
'colors' => Color::all(),
|
||||
'manufacturers' => Manufacturer::all(),
|
||||
'types' => Type::all()
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,110 @@
|
||||
namespace App\Livewire\Filament;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
use App\Models\Manufacturer as Model;
|
||||
use Livewire\Attributes\title;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Flux\Flux;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
#[title('Manufacturer List')]
|
||||
class Manufacturer extends Component{
|
||||
use WithPagination;
|
||||
|
||||
#[Validate('required')]
|
||||
public $name = '';
|
||||
|
||||
public $description = '';
|
||||
public $website = '';
|
||||
|
||||
public $search ='';
|
||||
|
||||
public $editid = '';
|
||||
public $deleteid = '';
|
||||
|
||||
public function create() {
|
||||
@Auth::check();
|
||||
|
||||
|
||||
// Validate
|
||||
$this->validate();
|
||||
|
||||
$manufacturer = new Model();
|
||||
$manufacturer->name = $this->name;
|
||||
$manufacturer->description = $this->description;
|
||||
$manufacturer->website = $this->website;
|
||||
$manufacturer->save();
|
||||
|
||||
// Clear the form
|
||||
$this->resetInputFields();
|
||||
|
||||
// Close the modal
|
||||
Flux::modal('createModal')->close();
|
||||
}
|
||||
public function edit($manufacturerid) {
|
||||
@Auth::check();
|
||||
|
||||
$editid = $manufacturerid;
|
||||
$this->editid = $editid;
|
||||
|
||||
$manufacturer = Model::findOrFail($editid);
|
||||
|
||||
$this->name = $manufacturer->name;
|
||||
$this->description = $manufacturer->description;
|
||||
$this->website = $manufacturer->website;
|
||||
|
||||
Flux::modal('editModal')->show();
|
||||
}
|
||||
public function save($editid) {
|
||||
@Auth::check();
|
||||
|
||||
$manufacturer = Model::findOrFail($editid);
|
||||
$manufacturer->name = $this->name;
|
||||
$manufacturer->description = $this->description;
|
||||
$manufacturer->website = $this->website;
|
||||
$manufacturer->save();
|
||||
|
||||
$this->resetInputFields();
|
||||
|
||||
Flux::modal('editModal')->close();
|
||||
}
|
||||
public function deleteModal($manufacturerid) {
|
||||
@Auth::check();
|
||||
|
||||
$deleteid = $manufacturerid;
|
||||
$this->deleteid = $deleteid;
|
||||
|
||||
$manufacturer = Model::findOrFail($deleteid);
|
||||
$this->name = $manufacturer->name;
|
||||
$this->description = $manufacturer->description;
|
||||
$this->website = $manufacturer->website;
|
||||
|
||||
Flux::modal('deleteModal')->show();
|
||||
}
|
||||
public function delete($deleteid) {
|
||||
@Auth::check();
|
||||
|
||||
$manufacturer = Model::findOrFail($deleteid)->delete();
|
||||
|
||||
$this->deleteid = $deleteid;
|
||||
Flux::modal('deleteModal')->close();
|
||||
|
||||
// Clear the form
|
||||
$this->resetInputFields();
|
||||
}
|
||||
public function cancel() {
|
||||
$this->resetInputFields();
|
||||
Flux::modals()->close();
|
||||
}
|
||||
public function resetInputFields() {
|
||||
$this->reset(['name', 'description', 'website', 'deleteid', 'editid']);
|
||||
}
|
||||
|
||||
class Manufacturer extends Component
|
||||
{
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.filament.manufacturer');
|
||||
return view('livewire.filament.manufacturer', [
|
||||
'manufacturers' => Model::search('name', $this->search)->paginate(10)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user