Reputation: 1654
I'm changing AuthenticatesUsers.php to use google recaptcha in postLogin method.
Have a trait
<?php
namespace App\Traits;
use Illuminate\Support\Facades\Input;
use ReCaptcha\ReCaptcha;
trait CaptchaTrait {
public function captchaCheck()
{
...
}
}
and my AuthenticatesUsers.php
starts with
<?php
namespace Illuminate\Foundation\Auth;
use App\Traits\CaptchaTrait;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Lang;
trait AuthenticatesUsers
{
use RedirectsUsers;
use CaptchaTrait;
...
}
In login page, I get this error
FatalErrorException in AuthenticatesUsers.php line 13: Trait
'App\Traits\CaptchaTrait' not found
Can't understand why. In PhpStorm when importing class CaptchaTrait it automatically import App\Traits\CaptchaTrait to AuthenticatesUsers.php
What am I missing?
Upvotes: 0
Views: 1621
Reputation: 35357
Look at your composer.json file for more information on what the App namespace is. It's a link to the app/ directory (PSR-4).
So the namespace App\Traits is equivalent to the directory app/Traits, not app/App/Traits. The namespace and directories have to match what is defined in your composer autoloader, otherwise, it won't know how to load the class/trait/interface.
Upvotes: 3