Skip to content

Commit 0498c8f

Browse files
committed
laravel 8 support
1 parent 1b8d46f commit 0498c8f

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@
1515
"name": "Bhavin Gajjar",
1616
"email": "[email protected]",
1717
"role": "Developer"
18+
},
19+
{
20+
"name": "Dipesh Sukhia",
21+
"email": "[email protected]",
22+
"role": "Developer"
1823
}
1924
],
2025
"require": {
2126
"php": "^7.2",
22-
"illuminate/support": "5.8.*|^6.0|^7.0"
27+
"illuminate/support": "5.8.*|^6.0|^7.0|^8.0"
2328
},
2429
"require-dev": {
2530
"orchestra/testbench": "3.8.*",

config/config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
| Example: 'app/Model' or 'app/model' or 'app/Models' or 'app/Data/Model' etc...
1414
|
1515
*/
16-
'model_directory_path' => 'app',
16+
17+
'model_directory_path' => is_dir(base_path('app/Models')) ? 'app/Models':'app',
1718

1819
'allow_cross_origin' => env('API_ALLOW_CROSS_ORIGIN', false),
1920
'json_response' => env('API_JSON_RESPONSE', true),

src/LaravelApiGenerator.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public function generateController()
3939
$template = str_replace('{{modelName}}', $this->model, $template);
4040
$template = str_replace('{{modelNameLower}}', strtolower($this->model), $template);
4141
$template = str_replace('{{modelNameCamel}}', Str::camel($this->model), $template);
42+
$template = str_replace('{{modelNameSpace}}', is_dir(base_path('app/Models')) ? 'Models\\'.$this->model : $this->model, $template);
43+
4244
file_put_contents(base_path('app/Http/Controllers/Api/'.$this->model.'Controller.php'), $template);
4345
$this->result = true;
4446
}
@@ -50,7 +52,11 @@ public function generateResource()
5052
{
5153
$this->result = false;
5254
if (! file_exists(base_path('app/Http/Resources/'.$this->model.'Resource.php'))) {
53-
$model = app('App\\'.$this->model);
55+
if(is_dir(base_path('app/Models'))){
56+
$model = app('App\\Models\\'.$this->model);
57+
}else{
58+
$model = app('App\\'.$this->model);
59+
}
5460
$columns = $model->getConnection()->getSchemaBuilder()->getColumnListing($model->getTable());
5561
$print_columns = null;
5662
foreach ($columns as $key => $column) {

src/resources/stubs/controller.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use App\Http\Controllers\Controller;
66
use Exception;
77
use Illuminate\Http\JsonResponse;
88
use Illuminate\Http\Request;
9-
use App\{{modelName}};
9+
use App\{{modelNameSpace}};
1010
use App\Http\Resources\{{modelName}}Resource;
1111
use App\Http\Resources\{{modelName}}Collection;
1212

0 commit comments

Comments
 (0)