-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGenerateAuthPermissionsCommand.php
53 lines (39 loc) · 1.75 KB
/
GenerateAuthPermissionsCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Javaabu\Generators\Commands\Auth;
use Javaabu\Generators\Generators\Auth\AuthPermissionsGenerator;
use Javaabu\Generators\Generators\Auth\BaseAuthGenerator;
class GenerateAuthPermissionsCommand extends BaseAuthGenerateCommand
{
protected $name = 'generate:auth_permissions';
protected $description = 'Generate auth permissions based on your database table schema';
protected string $generator_class = AuthPermissionsGenerator::class;
protected function createOutput(string $table, array $columns, string $auth_name): void
{
$generator = $this->getGenerator($table, $columns, $auth_name);
$output = $generator->render();
if (app()->runningInConsole()) {
$this->info("Schema-based auth permissions for table \"$table\" have been generated!");
$this->info('Copy & paste these to your permissions seeder file:');
}
$this->line($output);
}
protected function createFiles(string $table, array $columns, string $auth_name, bool $force = false, string $path = ''): void
{
$path = $this->getPath(database_path('seeders'), $path);
$stub = 'generators::seeders/PermissionsSeeder.stub';
$file_name = 'PermissionsSeeder.php';
$file_path = $this->getFullFilePath($path, $file_name);
$generator = $this->getGenerator($table, $columns, $auth_name);
$output = $generator->render();
$replacements = [
[
'search' => 'protected $data = ['."\n",
'keep_search' => true,
'content' => $output . "\n",
],
];
if ($this->appendContent($file_path, $replacements, $stub)) {
$this->info("$table auth permissions created!");
}
}
}