When following laravel conventions you shouldn't need the new keyword.
Perhaps reread the the Chapter on Authentication, maybe you're missing something.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a class IndexController class with its own method verifyUser.
public function verifyUser($user) {
echo "Test!";
}
Its actual code isn't as important as the nature that it isn't called when I want it to be.
It works perfectly fine in its base class, but when I try to call it in other classes I get different results:
$this->indexController = new IndexController();
$this->indexController->verifyUser(auth()->user());
I can confirm that auth()->user() is fine. The error message I get is something else: Call to undefined method: IndexController::verifyUser()
I can reword the call in a few different ways, such as:
IndexController::verifyUser(auth()->user());
Or
$thing = $this->indexController->verifyUser(auth()->user());
But it doesn't fit it.
I note that if I simply paste the code that verifyUser has into my new class, it works just fine. It's just this one form of method calling. I don't get why it works. Could anyone shed some light on why I might be getting this issue?
Create a class in some folder within app folder like Verification
namespace App\Verification;
UserVerification {
public static function verify(User $user) {
// logic here
}
}
And then call it from any controller like:
\App\Verification\UserVerification::verify($user);
Please or to participate in this conversation.