Last active
November 18, 2022 03:35
-
-
Save umefarooq/ebc617dbf88260db1448 to your computer and use it in GitHub Desktop.
Laravel 5.2 make:view command thanks to https://gist.github.com/sahibalejandro/1030d43259a6fe95f79f
This file contains 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; | |
use File; | |
class MakeViewCommand extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'make:view {view}'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Create a new blade template.'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
$view = $this->argument('view'); | |
$path = $this->viewPath($view); | |
$this->createDir($path); | |
if (File::exists($path)) | |
{ | |
$this->error("File {$path} already exists!"); | |
return; | |
} | |
File::put($path, $path); | |
$this->info("File {$path} created."); | |
} | |
/** | |
* Get the view full path. | |
* | |
* @param string $view | |
* | |
* @return string | |
*/ | |
public function viewPath($view) | |
{ | |
$view = str_replace('.', '/', $view) . '.blade.php'; | |
$path = "resources/views/{$view}"; | |
return $path; | |
} | |
/** | |
* Create view directory if not exists. | |
* | |
* @param $path | |
*/ | |
public function createDir($path) | |
{ | |
$dir = dirname($path); | |
if (!file_exists($dir)) | |
{ | |
mkdir($dir, 0777, true); | |
} | |
} | |
} |
what is command name
make:view
In my local it could not fine use File;
You need to use Illuminate\Support\Facades\File;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what is command name