Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save kennethsolomon/6c440df59a870575b48a985c10874bec to your computer and use it in GitHub Desktop.

Select an option

Save kennethsolomon/6c440df59a870575b48a985c10874bec to your computer and use it in GitHub Desktop.
Creating Services using php artisan command
# /config/filesystems.php
# add this inside 'disk' array
'services' => [
'driver' => 'local',
'root' => 'app/Services',
'throw' => false,
],
# /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