Implementacion de modulo de pedidos
This commit is contained in:
79
app/Http/Livewire/RutaController.php
Normal file
79
app/Http/Livewire/RutaController.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Ruta;
|
||||
use Livewire\Component;
|
||||
|
||||
class RutaController extends Component
|
||||
{
|
||||
public $ruta, $buscador, $modal = false;
|
||||
|
||||
protected $rules = [
|
||||
'ruta.ruta' => 'required',
|
||||
'ruta.prefijo' => 'required',
|
||||
];
|
||||
public function render()
|
||||
{
|
||||
$rutas = Ruta::where('ruta','like','%'.$this->buscador.'%')->paginate(10);
|
||||
return view('ruta.ruta',[
|
||||
'rutas' => $rutas,
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->clearInputs();
|
||||
$this->ruta = new Ruta();
|
||||
$this->showModal();
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate([
|
||||
'ruta.ruta' => 'required|max:50',
|
||||
'ruta.prefijo' => 'required|max:10',
|
||||
]);
|
||||
|
||||
$id = $this->ruta->id;
|
||||
|
||||
$this->ruta->save();
|
||||
|
||||
session()->flash('message',$id?"La ruta se a modificado correctamente.":"La ruta se ha registrado correctamente!");
|
||||
|
||||
$this->clearInputs();
|
||||
$this->closeModal();
|
||||
}
|
||||
|
||||
public function edit(Ruta $ruta)
|
||||
{
|
||||
$this->ruta = $ruta;
|
||||
$this->showModal();
|
||||
}
|
||||
|
||||
public function delete(Ruta $ruta)
|
||||
{
|
||||
|
||||
if(auth()->user()->hasRole('admin'))
|
||||
{
|
||||
$ruta->delete();
|
||||
session()->flash('message',"La ruta se ha eliminado del sistema.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function showModal()
|
||||
{
|
||||
$this->modal = true;
|
||||
}
|
||||
|
||||
public function closeModal()
|
||||
{
|
||||
$this->modal = false;
|
||||
}
|
||||
|
||||
public function clearInputs()
|
||||
{
|
||||
$this->reset();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user