roles por subvendedor
This commit is contained in:
@@ -1,49 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Livewire\Component;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
|
||||
class ShowRoles extends Component
|
||||
{
|
||||
use LivewireAlert;
|
||||
public $editar= false;
|
||||
|
||||
public $editar = false;
|
||||
public $nombre;
|
||||
public $add;
|
||||
public $ro;
|
||||
public $filtro_id;
|
||||
|
||||
public function render()
|
||||
{
|
||||
if (auth()->user()->rol_id == 5) {
|
||||
|
||||
$query = Role::withCount('usuarios');
|
||||
if ($this->filtro_id) {
|
||||
$query->where('subvendedor_id', $this->filtro_id);
|
||||
}
|
||||
$consulta_roles = $query->get();
|
||||
|
||||
$consulta_roles = Role::withCount('usuarios')->get();
|
||||
//dd($consulta_roles);
|
||||
return view('livewire.show-roles',['roles'=>$consulta_roles]);
|
||||
$consulta_usuarios = User::orderBy('name', 'asc')->get();
|
||||
} else {
|
||||
$consulta_roles = Role::where('subvendedor_id', auth()->user()->id)->withCount('usuarios')->get();
|
||||
$consulta_usuarios = null;
|
||||
}
|
||||
|
||||
return view('livewire.show-roles', [
|
||||
'roles' => $consulta_roles,
|
||||
'usuarios' => $consulta_usuarios
|
||||
]);
|
||||
}
|
||||
|
||||
public function editar($id){
|
||||
public function editar($id)
|
||||
{
|
||||
$this->nombre = Role::find($id)->nombre;
|
||||
$this->ro = $id;
|
||||
$this->editar = true;
|
||||
}
|
||||
|
||||
public function crear(){
|
||||
public function crear()
|
||||
{
|
||||
if (!empty($this->nombre)) {
|
||||
$crear_rol = new Role;
|
||||
$crear_rol->nombre = $this->nombre;
|
||||
$crear_rol->save();
|
||||
$crear_rol = new Role;
|
||||
$crear_rol->nombre = $this->nombre;
|
||||
$crear_rol->subvendedor_id = (auth()->user()->rol_id == 5) ? null : auth()->user()->id;
|
||||
$crear_rol->save();
|
||||
|
||||
$this->alert('success', 'Rol creado correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
$this->add = false;
|
||||
}else{
|
||||
$this->alert('success', 'Rol creado correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
$this->add = false;
|
||||
} else {
|
||||
$this->alert('warning', 'Campo Nombre sin diligenciar!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function eliminar($id)
|
||||
@@ -79,29 +98,29 @@ class ShowRoles extends Component
|
||||
|
||||
public function confirmed()
|
||||
{
|
||||
$eliminar= Role::find($this->ro)->delete();
|
||||
$eliminar = Role::find($this->ro)->delete();
|
||||
$this->alert('success', 'Rol eliminado!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function limpiarInputAdd(){
|
||||
$this->editar= false;
|
||||
public function limpiarInputAdd()
|
||||
{
|
||||
$this->editar = false;
|
||||
$this->add = false;
|
||||
|
||||
}
|
||||
|
||||
public function actualizar(){
|
||||
$eliminar= Role::find($this->ro);
|
||||
public function actualizar()
|
||||
{
|
||||
$eliminar = Role::find($this->ro);
|
||||
//dd($eliminar);
|
||||
$eliminar->update(['nombre'=>$this->nombre]);
|
||||
$eliminar->update(['nombre' => $this->nombre]);
|
||||
|
||||
$this->alert('success', 'Rol actualizado!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->editar=false;
|
||||
|
||||
$this->editar = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user