Skip to content

Commit 8da805d

Browse files
committed
facade argument missing issue fixed
1 parent 2c8acd6 commit 8da805d

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/Commands/GenerateApi.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class GenerateApi extends Command
2323
/**
2424
* Create a new command instance.
2525
*
26-
* @return void
2726
*/
2827
public function __construct()
2928
{
@@ -37,6 +36,12 @@ public function __construct()
3736
*/
3837
public function handle()
3938
{
39+
if(empty($this->option('model'))){
40+
$this->error('Model Name Argument not found!');
41+
42+
return false;
43+
}
44+
4045
if (! file_exists(base_path(config('laravel-api-generator.model_directory_path').'/'.$this->option('model').'.php'))) {
4146
$this->error('Model does not exist!');
4247

src/LaravelApiGenerator.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function directoryCreate()
3434
public function generateController()
3535
{
3636
if (! file_exists(base_path('app/Http/Controllers/Api/'.$this->model.'Controller.php'))) {
37-
$template = file_get_contents(self::STUB_DIR.'controller.stub');
37+
$template = self::getStubContents('controller.stub');
3838
$template = str_replace('{{modelName}}', $this->model, $template);
3939
$template = str_replace('{{modelNameLower}}', strtolower($this->model), $template);
4040
$template = str_replace('{{modelNameCamel}}', Str::camel($this->model), $template);
@@ -48,7 +48,7 @@ public function generateController()
4848
public function generateResource()
4949
{
5050
if (! file_exists(base_path('app/Http/Resources/'.$this->model.'Resource.php'))) {
51-
$template = file_get_contents(self::STUB_DIR.'resource.stub');
51+
$template = self::getStubContents('resource.stub');
5252
$template = str_replace('{{modelName}}', $this->model, $template);
5353
file_put_contents(base_path('app/Http/Resources/'.$this->model.'Resource.php'), $template);
5454
$this->result = true;
@@ -60,7 +60,7 @@ public function generateResource()
6060
public function generateCollection()
6161
{
6262
if (! file_exists(base_path('app/Http/Resources/'.$this->model.'Collection.php'))) {
63-
$template = file_get_contents(self::STUB_DIR.'collection.stub');
63+
$template = self::getStubContents('collection.stub');
6464
$template = str_replace('{{modelName}}', $this->model, $template);
6565
file_put_contents(base_path('app/Http/Resources/'.$this->model.'Collection.php'), $template);
6666
$this->result = true;
@@ -81,4 +81,8 @@ public function generateRoute()
8181

8282
return $this->result;
8383
}
84+
85+
private function getStubContents($stubName){
86+
return file_get_contents(self::STUB_DIR.$stubName);
87+
}
8488
}

src/LaravelApiGeneratorFacade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Illuminate\Support\Facades\Facade;
66

77
/**
8-
* @see \Bhavingajjar\LaravelApiGenerator\Skeleton\SkeletonClass
8+
* @see \Bhavingajjar\LaravelApiGenerator\LaravelApiGenerator
99
*/
1010
class LaravelApiGeneratorFacade extends Facade
1111
{

src/LaravelApiGeneratorServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public function register()
5656
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-api-generator');
5757

5858
// Register the main class to use with the facade
59-
$this->app->singleton('laravel-api-generator', function () {
60-
return new LaravelApiGenerator;
59+
$this->app->singleton('laravel-api-generator', function (string $model) {
60+
return new LaravelApiGenerator($model);
6161
});
6262
}
6363
}

0 commit comments

Comments
 (0)