diff --git a/resources/stubs/Controller.stub b/resources/stubs/Controller.stub index 9e9789c..f87f586 100644 --- a/resources/stubs/Controller.stub +++ b/resources/stubs/Controller.stub @@ -7,12 +7,15 @@ use {{baseNamespace}}\{{moduleName}}\Models\{{modelName}}; use {{baseNamespace}}\{{moduleName}}\Repositories\{{modelName}}Repository; use {{baseNamespace}}\{{moduleName}}\Http\Requests\{{modelName}}Request; use {{baseNamespace}}\{{moduleName}}\Http\Resources\{{modelName}}Resource; +use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\ResourceCollection; use Illuminate\Http\Response; class {{controllerName}} extends Controller { + use AuthorizesRequests; + public function __construct(protected {{modelName}}Repository $repository) { $this->authorizeResource({{modelName}}::class); @@ -27,7 +30,7 @@ class {{controllerName}} extends Controller public function store({{modelName}}Request $request): {{modelName}}Resource { - ${{variableName}} = $this->repository->setRequest($request)->store($request->validated()); + ${{variableName}} = {{modelName}}::query()->create($request->validated()); return new {{modelName}}Resource(${{variableName}}); } diff --git a/src/Generators/CombinedGenerator.php b/src/Generators/CombinedGenerator.php index 64d950d..bf532e6 100644 --- a/src/Generators/CombinedGenerator.php +++ b/src/Generators/CombinedGenerator.php @@ -24,6 +24,7 @@ public function generators(): array RepositoryGenerator::class, RequestGenerator::class, ResourceGenerator::class, + PermissionSeederGenerator::class, ]; } diff --git a/src/Generators/ResourceGenerator.php b/src/Generators/ResourceGenerator.php index a3a0d2f..6a48c13 100644 --- a/src/Generators/ResourceGenerator.php +++ b/src/Generators/ResourceGenerator.php @@ -16,7 +16,7 @@ public function className(): string public function mixin(): string { - return sprintf('%s\%s\Models\%s', $this->baseNamespace(), $this->module(), $this->name()); + return sprintf('\%s\%s\Models\%s', $this->baseNamespace(), $this->module(), $this->name()); } public function replacements(): array diff --git a/tests/Generators/CombinedGeneratorTest.php b/tests/Generators/CombinedGeneratorTest.php index 93ac86e..e77aff6 100644 --- a/tests/Generators/CombinedGeneratorTest.php +++ b/tests/Generators/CombinedGeneratorTest.php @@ -22,6 +22,7 @@ public function testGenerateAllFiles(): void 'app/Modules/Posts/Repositories/CommentRepository.php', 'app/Modules/Posts/Http/Requests/CommentRequest.php', 'app/Modules/Posts/Http/Resources/CommentResource.php', + 'app/Modules/Posts/Seeders/CommentPermissionSeeder.php', ]; $this->assertEquals($expectedGeneratedFiles, $generator->generatedFiles()); diff --git a/tests/Generators/ResourceGeneratorTest.php b/tests/Generators/ResourceGeneratorTest.php index 62ebc3f..7e32b8b 100644 --- a/tests/Generators/ResourceGeneratorTest.php +++ b/tests/Generators/ResourceGeneratorTest.php @@ -33,7 +33,7 @@ public static function dataModelWriteTest(): array 'expectedStrings' => [ 'class PostResource extends JsonResource', 'namespace App\Modules\Posts\Http\Resources;', - '@mixin App\Modules\Posts\Models\Post', + '@mixin \App\Modules\Posts\Models\Post', ], ], ];