laravel-ide-helper
laravel-ide-helper copied to clipboard
Fix return type of `user` method inside form requests
Summary
The return type of $this->user()
inside a form request is mixed
instead of User
.
When calling the same method from outside the form request the return type is correct $request->user() // User|null
.
Code example
/**
* @mixin IdeHelperUser
*/
class User extends Authenticatable
{
//
}
class UserController
{
public function index(GetUsersRequest $request)
{
$user = $request->user(); // User|null
$user->id; // `id` is auto-completed
}
}
class GetUsersRequest extends FormRequest
{
public function authorize(): bool
{
$user = $this->user(); // mixed
$user->id; // `id` isn't auto-completed
}
}