77 lines
1.6 KiB
PHP
77 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Rol;
|
|
use Cartalyst\Sentinel\Native\Facades\Sentinel;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Route;
|
|
use Log;
|
|
|
|
class RolePermissions extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'permisos';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Actualiza permisos del root';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$roles = Rol::select('name')->orderBy('id')->get();
|
|
|
|
$procesos = array('Salir');
|
|
|
|
foreach ($roles as $r){
|
|
array_push($procesos, $r->name);
|
|
}
|
|
|
|
$proceso = $this->choice('Proceso ?', $procesos, 0);
|
|
|
|
if($proceso == 'Salir'){
|
|
$this->info('BYE :)');
|
|
dd();
|
|
}
|
|
|
|
$rolName = $proceso;
|
|
$this->info('Actualizando permisos para: ' . $rolName);
|
|
$role = Sentinel::findRoleByName($rolName);
|
|
|
|
$permisos = [];
|
|
$routeCollection = Route::getRoutes();
|
|
foreach ($routeCollection as $value) {
|
|
if($value->getName()!=""){
|
|
$permisos[$value->getName()] = true;
|
|
}
|
|
}
|
|
$role->permissions = $permisos;
|
|
$role->save();
|
|
|
|
$this->info('Permisos actualizados para rol: ' . $rolName);
|
|
|
|
}
|
|
}
|