Created
January 3, 2023 08:39
-
-
Save kennethsolomon/6c440df59a870575b48a985c10874bec to your computer and use it in GitHub Desktop.
Creating Services using php artisan command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create Services |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /config/filesystems.php | |
| # add this inside 'disk' array | |
| 'services' => [ | |
| 'driver' => 'local', | |
| 'root' => 'app/Services', | |
| 'throw' => false, | |
| ], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /app/Console/Commands | |
| # or Run the command -> php artisan make:command MakeService | |
| <?php | |
| namespace App\Console\Commands; | |
| use Illuminate\Console\Command; | |
| use Illuminate\Support\Facades\Storage; | |
| class MakeService extends Command | |
| { | |
| /** | |
| * The name and signature of the console command. | |
| * | |
| * @var string | |
| */ | |
| protected $signature = 'make:service {file_name}'; | |
| /** | |
| * The console command description. | |
| * | |
| * @var string | |
| */ | |
| protected $description = 'Create Service File'; | |
| /** | |
| * Execute the console command. | |
| * | |
| * @return int | |
| */ | |
| public function handle() | |
| { | |
| // $this->argument('user') | |
| Storage::disk('services')->put($this->argument('file_name') . '.php', $this->services()); | |
| } | |
| public function services() | |
| { | |
| return | |
| '<?php | |
| namespace App\Services; | |
| class ' . $this->argument('file_name') . ' | |
| { | |
| private static $instance = null; | |
| public static function getInstance() | |
| { | |
| if (self::$instance == null) { | |
| self::$instance = new self; | |
| } | |
| return self::$instance; | |
| } | |
| public function Foobar() | |
| { | |
| // Code Here.. | |
| } | |
| }'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment