Skip to content

Commit 5e673af

Browse files
Respect model namespace when guessing (#719)
1 parent 90730bf commit 5e673af

File tree

7 files changed

+13
-5
lines changed

7 files changed

+13
-5
lines changed

src/Generators/ControllerGenerator.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,13 @@ private function fullyQualifyModelReference(string $sub_namespace, string $model
222222
return $model->fullyQualifiedClassName();
223223
}
224224

225-
return config('blueprint.namespace') . '\\' . ($sub_namespace ? $sub_namespace . '\\' : '') . $model_name;
225+
return sprintf(
226+
'%s\\%s%s%s',
227+
config('blueprint.namespace'),
228+
config('blueprint.models_namespace') ? config('blueprint.models_namespace') . '\\' : '',
229+
$sub_namespace ? $sub_namespace . '\\' : '',
230+
$model_name
231+
);
226232
}
227233

228234
private function determineModel(Controller $controller, ?string $reference): string

tests/Feature/Generators/ControllerGeneratorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public function output_respects_configuration(): void
130130
{
131131
$this->app['config']->set('blueprint.app_path', 'src/path');
132132
$this->app['config']->set('blueprint.namespace', 'Some\\App');
133+
$this->app['config']->set('blueprint.models_namespace', '');
133134
$this->app['config']->set('blueprint.controllers_namespace', 'Other\\Http');
134135

135136
$this->filesystem->expects('stub')

tests/fixtures/controllers/inertia-render.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace App\Http\Controllers;
44

5-
use App\Customer;
5+
use App\Models\Customer;
66
use Illuminate\Http\Request;
77
use Inertia\Inertia;
88
use Inertia\Response;

tests/fixtures/controllers/with-all-policies.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use App\Http\Requests\PostStoreRequest;
66
use App\Http\Requests\PostUpdateRequest;
7-
use App\Post;
7+
use App\Models\Post;
88
use Illuminate\Http\RedirectResponse;
99
use Illuminate\Http\Request;
1010
use Illuminate\Support\Facades\Gate;

tests/fixtures/controllers/with-authorize-resource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use App\Http\Requests\PostStoreRequest;
66
use App\Http\Requests\PostUpdateRequest;
7-
use App\Post;
7+
use App\Models\Post;
88
use Illuminate\Http\RedirectResponse;
99
use Illuminate\Http\Request;
1010
use Illuminate\View\View;

tests/fixtures/controllers/with-some-policies.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use App\Http\Requests\PostStoreRequest;
66
use App\Http\Requests\PostUpdateRequest;
7-
use App\Post;
7+
use App\Models\Post;
88
use Illuminate\Http\RedirectResponse;
99
use Illuminate\Http\Request;
1010
use Illuminate\Support\Facades\Gate;

tests/fixtures/drafts/controller-configured.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ controllers:
1313
config:
1414
app_path: shift
1515
namespace: Some\App
16+
models_namespace: null
1617
controllers_namespace: Other\Http

0 commit comments

Comments
 (0)