You can use Auth() class here to get current user and check permissions if needed.
You can also just use $this->user() since you’re in a form request and it extends Laravel’s Request class.
You can also drop the authorize method if all you do is return true. Form requests will only invoke it if it exists; otherwise it’ll just let the request through.
Your “user store service” is also more like a command or “action” rather than a user service class. If you resolve it from the container, you should inject the hasher instance instead of relying on a facade again so you can easily test it without the framework needing to be booted:
Good points! Usually I like to use facades because they are really easy to test with Laravel and it's something common, but it's true that you need to load the framework for that. 😉
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You can also just use
$this->user()
since you’re in a form request and it extends Laravel’sRequest
class.You can also drop the
authorize
method if all you do is return true. Form requests will only invoke it if it exists; otherwise it’ll just let the request through.Your “user store service” is also more like a command or “action” rather than a user service class. If you resolve it from the container, you should inject the hasher instance instead of relying on a facade again so you can easily test it without the framework needing to be booted:
Good points! Usually I like to use facades because they are really easy to test with Laravel and it's something common, but it's true that you need to load the framework for that. 😉