Skip to content

Commit

Permalink
Support custom user provider names in generator commands
Browse files Browse the repository at this point in the history
  • Loading branch information
markwalet committed Sep 18, 2018
1 parent 0ff8413 commit 3bb7059
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/Illuminate/Console/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected function replaceNamespace(&$stub, $name)
{
$stub = str_replace(
['DummyNamespace', 'DummyRootNamespace', 'NamespacedDummyUserModel'],
[$this->getNamespace($name), $this->rootNamespace(), config('auth.providers.users.model')],
[$this->getNamespace($name), $this->rootNamespace(), $this->userProviderModel()],
$stub
);

Expand Down Expand Up @@ -223,6 +223,19 @@ protected function rootNamespace()
return $this->laravel->getNamespace();
}

/**
* Get the configured model for the provider.
*
* @return string|null
*/
protected function userProviderModel()
{
$guard = config('auth.defaults.guard');
$provider = config("auth.guards.{$guard}.provider");

return config("auth.providers.{$provider}.model");
}

/**
* Get the console command arguments.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Console/ChannelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function buildClass($name)
{
return str_replace(
'DummyUser',
class_basename(config('auth.providers.users.model')),
class_basename($this->userProviderModel()),
parent::buildClass($name)
);
}
Expand Down
7 changes: 4 additions & 3 deletions src/Illuminate/Foundation/Console/PolicyMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ protected function buildClass($name)
*/
protected function replaceUserNamespace($stub)
{
if (! config('auth.providers.users.model')) {
$model = $this->userProviderModel();
if (! $model) {
return $stub;
}

return str_replace(
$this->rootNamespace().'User',
config('auth.providers.users.model'),
$model,
$stub
);
}
Expand Down Expand Up @@ -90,7 +91,7 @@ protected function replaceModel($stub, $model)

$model = class_basename(trim($model, '\\'));

$dummyUser = class_basename(config('auth.providers.users.model'));
$dummyUser = class_basename($this->userProviderModel());

$dummyModel = Str::camel($model) === 'user' ? 'model' : $model;

Expand Down

0 comments on commit 3bb7059

Please sign in to comment.