File tree 4 files changed +57
-4
lines changed
4 files changed +57
-4
lines changed Original file line number Diff line number Diff line change
1
+ # Laravel API Resource Generator Package
2
+
3
+ This package will help you to generate API resources for your Laravel project.
4
+
5
+ ## Installation
6
+
7
+ You can install the package via composer:
8
+
9
+ ``` bash
10
+ composer require alibori/laravel-api-resource-generator
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ``` bash
16
+ php artisan alibori:api-resource < model-name>
17
+ ```
18
+
19
+ ## Publish config file
20
+
21
+ ``` bash
22
+ php artisan vendor:publish --provider=" Alibori\LaravelApiResourceGenerator\LaravelApiResourceGeneratorServiceProvider" --tag=" config"
23
+ ```
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is the "config" file of the Laravel Api Resource Generator package.
5
+ */
6
+
7
+ return [
8
+ 'resources ' => [
9
+ 'dir ' => 'app/Http/Resources ' ,
10
+ 'namespace ' => 'App \\Http \\Resources ' ,
11
+ ],
12
+ 'models ' => [
13
+ 'dir ' => 'app/Models ' ,
14
+ 'namespace ' => 'App \\Models ' ,
15
+ ],
16
+ ];
Original file line number Diff line number Diff line change 11
11
use Illuminate \Database \Eloquent \Model ;
12
12
use Illuminate \Filesystem \Filesystem ;
13
13
use Illuminate \Support \Str ;
14
- use ReflectionClass ;
15
14
use Symfony \Component \Console \Input \InputArgument ;
16
15
17
16
class GenerateApiResourceCommand extends Command
@@ -66,7 +65,7 @@ public function __construct(Filesystem $files)
66
65
public function handle (): void
67
66
{
68
67
$ this ->dir = $ this ->defaultResourcesDir ();
69
- $ this ->namespace = ' App\Http\Resources ' ;
68
+ $ this ->namespace = config ( ' laravelapiresourcegeneratorpackage.resources.namespace ' ) ;
70
69
71
70
$ model = $ this ->loadModel ($ this ->argument ('model ' ));
72
71
@@ -84,7 +83,7 @@ protected function getArguments(): array
84
83
85
84
protected function defaultResourcesDir (): string
86
85
{
87
- return ' app/Http/Resources ' ;
86
+ return config ( ' laravelapiresourcegeneratorpackage.resources.dir ' ) ;
88
87
}
89
88
90
89
/**
@@ -93,7 +92,7 @@ protected function defaultResourcesDir(): string
93
92
protected function loadModel (string $ model ): Model
94
93
{
95
94
96
- return $ this ->laravel ->make (' App \\ Models \\' . $ model );
95
+ return $ this ->laravel ->make (config ( ' laravelapiresourcegeneratorpackage.models.namespace ' ) . ' \\' . $ model );
97
96
}
98
97
99
98
/**
Original file line number Diff line number Diff line change 9
9
10
10
class LaravelApiResourceGeneratorServiceProvider extends ServiceProvider
11
11
{
12
+ /**
13
+ * Register the application services.
14
+ *
15
+ * @return void
16
+ */
17
+ public function register (): void
18
+ {
19
+ $ this ->mergeConfigFrom (__DIR__ .'/../config/config.php ' , 'laravelapiresourcegeneratorpackage ' );
20
+ }
21
+
12
22
/**
13
23
* Bootstrap the application services.
14
24
*
@@ -21,5 +31,10 @@ public function boot(): void
21
31
}
22
32
23
33
$ this ->commands ([GenerateApiResourceCommand::class]);
34
+
35
+ // Publish config file
36
+ $ this ->publishes ([
37
+ __DIR__ .'/../config/config.php ' => config_path ('laravelapiresourcegeneratorpackage.php ' ),
38
+ ], 'config ' );
24
39
}
25
40
}
You can’t perform that action at this time.
0 commit comments