Skip to content

Commit bb36037

Browse files
authored
Merge pull request #10 from dipeshsukhia/master
Laravel 8 and php 8 support
2 parents 1b8d46f + 9d2e7da commit bb36037

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@
1515
"name": "Bhavin Gajjar",
1616
"email": "gajjarbhavin22@gmail.com",
1717
"role": "Developer"
18+
},
19+
{
20+
"name": "Dipesh Sukhia",
21+
"email": "dipsh.sukhia@gmail.com",
22+
"role": "Developer"
1823
}
1924
],
2025
"require": {
21-
"php": "^7.2",
22-
"illuminate/support": "5.8.*|^6.0|^7.0"
26+
"php": "^7.2|^8.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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ 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);
4243
file_put_contents(base_path('app/Http/Controllers/Api/'.$this->model.'Controller.php'), $template);
4344
$this->result = true;
4445
}
@@ -50,7 +51,7 @@ public function generateResource()
5051
{
5152
$this->result = false;
5253
if (! file_exists(base_path('app/Http/Resources/'.$this->model.'Resource.php'))) {
53-
$model = app('App\\'.$this->model);
54+
$model = is_dir(base_path('app/Models')) ? app('App\\Models\\'.$this->model) : app('App\\'.$this->model);
5455
$columns = $model->getConnection()->getSchemaBuilder()->getColumnListing($model->getTable());
5556
$print_columns = null;
5657
foreach ($columns as $key => $column) {
@@ -89,7 +90,6 @@ public function generateRoute()
8990
file_put_contents(base_path('routes/api.php'), $route, FILE_APPEND);
9091
$this->result = true;
9192
}
92-
9393
return $this->result;
9494
}
9595

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)