Skip to content

Commit

Permalink
Respect model namespace when guessing
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccreary committed Dec 18, 2024
1 parent 90730bf commit 48d1f1f
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/Generators/ControllerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,13 @@ private function fullyQualifyModelReference(string $sub_namespace, string $model
return $model->fullyQualifiedClassName();
}

return config('blueprint.namespace') . '\\' . ($sub_namespace ? $sub_namespace . '\\' : '') . $model_name;
return sprintf(
'%s\\%s%s%s',
config('blueprint.namespace'),
config('blueprint.models_namespace') ? config('blueprint.models_namespace') . '\\' : '',
$sub_namespace ? $sub_namespace . '\\' : '',
$model_name
);
}

private function determineModel(Controller $controller, ?string $reference): string
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/Generators/ControllerGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public function output_respects_configuration(): void
{
$this->app['config']->set('blueprint.app_path', 'src/path');
$this->app['config']->set('blueprint.namespace', 'Some\\App');
$this->app['config']->set('blueprint.models_namespace', '');
$this->app['config']->set('blueprint.controllers_namespace', 'Other\\Http');

$this->filesystem->expects('stub')
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/controllers/inertia-render.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Http\Controllers;

use App\Customer;
use App\Models\Customer;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/controllers/with-all-policies.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Http\Requests\PostStoreRequest;
use App\Http\Requests\PostUpdateRequest;
use App\Post;
use App\Models\Post;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/controllers/with-authorize-resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Http\Requests\PostStoreRequest;
use App\Http\Requests\PostUpdateRequest;
use App\Post;
use App\Models\Post;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/controllers/with-some-policies.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Http\Requests\PostStoreRequest;
use App\Http\Requests\PostUpdateRequest;
use App\Post;
use App\Models\Post;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/drafts/controller-configured.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ controllers:
config:
app_path: shift
namespace: Some\App
models_namespace: null
controllers_namespace: Other\Http

0 comments on commit 48d1f1f

Please sign in to comment.