114 lines
2.8 KiB
PHP
114 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Manufacturer;
|
|
|
|
use App\Models\Manufacturer as Model;
|
|
use Flux\Flux;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Livewire\Attributes\title;
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Component;
|
|
use Livewire\WithPagination;
|
|
|
|
#[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']);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
|
|
return view('livewire.manufacturer.index', [
|
|
'manufacturers' => Model::search('name', $this->search)->paginate(10)
|
|
]);
|
|
}
|
|
}
|