Skip to content

[5.4] Use the correct user model namespace in make:policy Command - #19965

Merged
taylorotwell merged 6 commits into
laravel:5.4from
Lloople:5.4
Jul 10, 2017
Merged

[5.4] Use the correct user model namespace in make:policy Command#19965
taylorotwell merged 6 commits into
laravel:5.4from
Lloople:5.4

Conversation

@Lloople

@Lloople Lloople commented Jul 8, 2017

Copy link
Copy Markdown
Contributor

I've been creating new policies this days in a project where my models are under app/Models directory.

Every policy I created I needed to modify the namespace of the user's model.

I remembered that this information is available through the auth configuration file and ended up with this.

I want to thank @JosephSilber who taught me a lot on this Gates & Policies stuff.

* Replace the user model for the given stub.
*
* @param string $stub
* @return string mixed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@return string mixed isn't valid, should be just @return string

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, didn't notice that

@tillkruss tillkruss changed the title Use the correct user model namespace in make:policy Command [5.4] Use the correct user model namespace in make:policy Command Jul 8, 2017
@taylorotwell

Copy link
Copy Markdown
Member

Hard-coding App will not work if people have changed the namespace of their application.

@Lloople

Lloople commented Jul 8, 2017

Copy link
Copy Markdown
Contributor Author

@taylorotwell Right, working on a fix

*/
protected function replaceUserModelNamespace($stub)
{
return str_replace($this->rootNamespace().'User', config('auth.providers.users.model'), $stub);

@4refael 4refael Jul 8, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A slight improvement

if ($this->rootNamespace().'User' !== config('auth.providers.users.model')) {
	return str_replace($this->rootNamespace().'User', config('auth.providers.users.model'), $stub);
}
return $stub;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants