Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Jul 10, 2017
Merged

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

merged 6 commits into from
Jul 10, 2017

Conversation

Lloople
Copy link
Contributor

@Lloople Lloople commented Jul 8, 2017

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
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
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
Member

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

@Lloople
Copy link
Contributor Author

Lloople commented Jul 8, 2017

@taylorotwell Right, working on a fix

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

@4refael 4refael Jul 8, 2017

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