Skip to content

Commit 4d0d883

Browse files
authored
[7.x] Publish resources.stub in stub:publish command (#33862)
* [7.x] Add a new helper to determine the true parent of a class. Some examples of use are: ```php class_parent_initial(HasMany::class); // Returns Relation::class class_parent_initial(HasOne::class); // Returns Relation::class class_parent_initial(HasOneOrMany::class); // Returns Relation::class ``` * [7.x] Publish resources.stub in stub:publish command * Remove parent_class helper * Update stub resources to match the format of the other publishable stubs.
1 parent 7cd8ca8 commit 4d0d883

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

src/Illuminate/Foundation/Console/ResourceMakeCommand.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public function handle()
5151
protected function getStub()
5252
{
5353
return $this->collection()
54-
? __DIR__.'/stubs/resource-collection.stub'
55-
: __DIR__.'/stubs/resource.stub';
54+
? $this->resolveStubPath('/stubs/resource-collection.stub')
55+
: $this->resolveStubPath('/stubs/resource.stub');
5656
}
5757

5858
/**
@@ -66,6 +66,19 @@ protected function collection()
6666
Str::endsWith($this->argument('name'), 'Collection');
6767
}
6868

69+
/**
70+
* Resolve the fully-qualified path to the stub.
71+
*
72+
* @param string $stub
73+
* @return string
74+
*/
75+
protected function resolveStubPath($stub)
76+
{
77+
return file_exists($customPath = $this->laravel->basePath(trim($stub, '/')))
78+
? $customPath
79+
: __DIR__.$stub;
80+
}
81+
6982
/**
7083
* Get the default namespace for the class.
7184
*

src/Illuminate/Foundation/Console/StubPublishCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public function handle()
3838
__DIR__.'/stubs/model.pivot.stub' => $stubsPath.'/model.pivot.stub',
3939
__DIR__.'/stubs/model.stub' => $stubsPath.'/model.stub',
4040
__DIR__.'/stubs/request.stub' => $stubsPath.'/request.stub',
41+
__DIR__.'/stubs/resource.stub' => $stubsPath.'/resource.stub',
42+
__DIR__.'/stubs/resource-collection.stub' => $stubsPath.'/resource-collection.stub',
4143
__DIR__.'/stubs/test.stub' => $stubsPath.'/test.stub',
4244
__DIR__.'/stubs/test.unit.stub' => $stubsPath.'/test.unit.stub',
4345
realpath(__DIR__.'/../../Database/Console/Factories/stubs/factory.stub') => $stubsPath.'/factory.stub',

src/Illuminate/Foundation/Console/stubs/resource-collection.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace DummyNamespace;
3+
namespace {{ namespace }};
44

55
use Illuminate\Http\Resources\Json\ResourceCollection;
66

7-
class DummyClass extends ResourceCollection
7+
class {{ class }} extends ResourceCollection
88
{
99
/**
1010
* Transform the resource collection into an array.

src/Illuminate/Foundation/Console/stubs/resource.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace DummyNamespace;
3+
namespace {{ namespace }};
44

55
use Illuminate\Http\Resources\Json\JsonResource;
66

7-
class DummyClass extends JsonResource
7+
class {{ class }} extends JsonResource
88
{
99
/**
1010
* Transform the resource into an array.

0 commit comments

Comments
 (0)