Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saber13812002/a4acbeb1c3227f28fa7a3b4151eda453 to your computer and use it in GitHub Desktop.
Save saber13812002/a4acbeb1c3227f28fa7a3b4151eda453 to your computer and use it in GitHub Desktop.
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Permission as PermissionModel;
use App\PermissionRole;
use Illuminate\Support\Facades\Config;
class Permission extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'permission:run {option}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'php artisan permission:run sync';
/**
* Permission model.
*
* @var object
*/
private $permission;
private $permissionRole;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(PermissionModel $permission, PermissionRole $permissionRole)
// public function __construct()
{
parent::__construct();
$this->permission = $permission;
$this->permissionRole = $permissionRole;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->info('started:');
$details = $this->getDetails();
$permission = $this->permission->createPermission($details);
if ($permission) {
$this->display($permission);
$this->info('Please add this line to your permission.php file in config folder:');
$this->info('\'' . $details['apiRouteName'] . '\'' . ' => ' . '\'' . $details['description'] . '\'');
} else {
$this->info($details['apiRouteName'] . 'exist');
}
}
/**
* Ask for permission details.
*
* @return array
*/
private function getDetails(): array
{
$details['switch'] = $this->ask('permission like grmvoa g: guest r: register m:marketer v:vendor m:moderator a: admin');
$details['apiRouteName'] = $this->ask('api route name like this: api.customer.comments.like | admin.states.create | ajax.categories.list');
$details['description'] = $this->ask('description');
while (!$this->isValidSwitch($details['switch'])) {
if (!$this->isValidSwitch($details['switch'])) {
$this->error('incorrect switches');
}
}
return $details;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment