diff --git a/src/Illuminate/Foundation/Console/PolicyMakeCommand.php b/src/Illuminate/Foundation/Console/PolicyMakeCommand.php index d1cbef9dc1b8..87f59206256d 100644 --- a/src/Illuminate/Foundation/Console/PolicyMakeCommand.php +++ b/src/Illuminate/Foundation/Console/PolicyMakeCommand.php @@ -39,11 +39,48 @@ protected function buildClass($name) { $stub = parent::buildClass($name); + $stub = $this->replaceUserModelNamespace($stub); + $model = $this->option('model'); return $model ? $this->replaceModel($stub, $model) : $stub; } + /** + * Replace the user model namespace for the given stub. + * + * @param string $stub + * @return string + */ + protected function replaceUserModelNamespace($stub) + { + if ($this->getDefaultUserNamespace() != $this->getRealUserNamespace()) { + return str_replace($this->getDefaultUserNamespace(), $this->getRealUserNamespace(), $stub); + } + + return $stub; + } + + /** + * Get the default namespace for the user model. + * + * @return string + */ + public function getDefaultUserNamespace() + { + return $this->rootNamespace().'User'; + } + + /** + * Get the real namespace for the user model. + * + * @return string + */ + public function getRealUserNamespace() + { + return config('auth.providers.users.model'); + } + /** * Replace the model for the given stub. *