Skip to content

Commit

Permalink
Several fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
axyr committed Aug 14, 2024
1 parent 00d7816 commit a9be89f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion resources/stubs/Controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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}});
}
Expand Down
1 change: 1 addition & 0 deletions src/Generators/CombinedGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function generators(): array
RepositoryGenerator::class,
RequestGenerator::class,
ResourceGenerator::class,
PermissionSeederGenerator::class,
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Generators/ResourceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/Generators/CombinedGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion tests/Generators/ResourceGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
],
];
Expand Down

0 comments on commit a9be89f

Please sign in to comment.