ikechukwukalu /
sanctumauthstarter
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Ikechukwukalu\Sanctumauthstarter\Console\Commands; |
||
| 4 | |||
| 5 | use Illuminate\Console\Command; |
||
| 6 | use Illuminate\Filesystem\Filesystem; |
||
| 7 | use Illuminate\Support\Str; |
||
| 8 | use Symfony\Component\Finder\SplFileInfo; |
||
| 9 | |||
| 10 | class ControllersCommand extends Command |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * The name and signature of the console command. |
||
| 14 | * |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | protected $signature = 'sas:controllers'; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * The console command description. |
||
| 21 | * |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $description = 'Scaffold the authentication controllers'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Execute the console command. |
||
| 28 | * |
||
| 29 | * @return void |
||
| 30 | */ |
||
| 31 | public function handle() |
||
| 32 | { |
||
| 33 | if (! is_dir($directory = app_path('Http/Controllers/Auth'))) { |
||
| 34 | mkdir($directory, 0755, true); |
||
| 35 | } |
||
| 36 | |||
| 37 | if (! is_dir($directory = app_path('Http/Requests/Auth'))) { |
||
| 38 | mkdir($directory, 0755, true); |
||
| 39 | } |
||
| 40 | |||
| 41 | if (! is_dir($directory = app_path('Services/Auth'))) { |
||
| 42 | mkdir($directory, 0755, true); |
||
| 43 | } |
||
| 44 | |||
| 45 | $filesystem = new Filesystem; |
||
| 46 | |||
| 47 | collect($filesystem->allFiles(__DIR__.'/stubs/Controllers')) |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 48 | ->each(function (SplFileInfo $file) use ($filesystem) { |
||
| 49 | $filesystem->copy( |
||
| 50 | $file->getPathname(), |
||
| 51 | app_path('Http/Controllers/Auth/'.Str::replaceLast('.stub', '.php', $file->getFilename())) |
||
| 52 | ); |
||
| 53 | }); |
||
| 54 | |||
| 55 | collect($filesystem->allFiles(__DIR__.'/stubs/Requests')) |
||
| 56 | ->each(function (SplFileInfo $file) use ($filesystem) { |
||
| 57 | $filesystem->copy( |
||
| 58 | $file->getPathname(), |
||
| 59 | app_path('Http/Requests/Auth/'.Str::replaceLast('.stub', '.php', $file->getFilename())) |
||
| 60 | ); |
||
| 61 | }); |
||
| 62 | |||
| 63 | collect($filesystem->allFiles(__DIR__.'/stubs/Services')) |
||
| 64 | ->each(function (SplFileInfo $file) use ($filesystem) { |
||
| 65 | $filesystem->copy( |
||
| 66 | $file->getPathname(), |
||
| 67 | app_path('Services/Auth/'.Str::replaceLast('.stub', '.php', $file->getFilename())) |
||
| 68 | ); |
||
| 69 | }); |
||
| 70 | |||
| 71 | $this->components->info('Controllers, requests and services scaffolding generated successfully.'); |
||
| 72 | } |
||
| 73 | } |
||
| 74 |