Last active
December 31, 2016 20:39
-
-
Save ferdiunal/cacb539c347f80901124f20bf937a14b to your computer and use it in GitHub Desktop.
How to use it? >>>>> ` https://laravel.com/docs/5.3/artisan#registering-commands `
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
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
class CustomLink extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'custom:link {path_name}'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Create Storage Custom Folder Link'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
$path_name = $this->argument('path_name'); | |
$directory = storage_path('app/' . $path_name); | |
if (file_exists(public_path($path_name))) { | |
return $this->error("The 'public/$path_name' directory already exists."); | |
} | |
if (!file_exists($directory)) { | |
$this->error("The $directory directory not exists."); | |
$created = $this->confirm("Do you want to create a directory ?"); | |
if (!$created) { | |
return false; | |
} | |
mkdir($directory); | |
} | |
$this->laravel->make('files')->link($directory, public_path($path_name)); | |
$this->info("The [public/$path_name] directory has been linked."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment