Skip to content

Commit

Permalink
resource stub
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Sep 25, 2023
1 parent f18d6ca commit b6fbfcd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Console/Commands/ResourceMake.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Cone\Root\Console\Commands;

use Illuminate\Console\GeneratorCommand;
use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputOption;

class ResourceMake extends GeneratorCommand
{
Expand Down Expand Up @@ -44,4 +46,40 @@ protected function getDefaultNamespace($rootNamespace): string
{
return $rootNamespace.'\\Root\\Resources';
}

/**
* Build the class with the given name.
*
* @param string $name
*/
protected function buildClass($name): string
{
$class = parent::buildClass($name);

return $this->replaceModel($class);
}

/**
* Create a new method.
*/
public function replaceModel(string $class): string
{
$model = $this->option('model');

$model = str_replace('/', '\\', $model);

$model = sprintf('\\%s::class', trim($model, '\\'));

return str_replace('{{ model }}', $model, $class);
}

/**
* Get the console command options.
*/
protected function getOptions(): array
{
return [
['model', null, InputOption::VALUE_OPTIONAL, 'The Eloquent Model'],
];
}
}
5 changes: 5 additions & 0 deletions stubs/Resource.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ use Illuminate\Http\Request;

class {{ class }} extends Resource
{
/**
* The model class.
*/
protected string $model = {{ model }};

/**
* Define the widgets for the resource.
*/
Expand Down

0 comments on commit b6fbfcd

Please sign in to comment.