2015-12-30 31 views
0

我在變AuthenticatesUsers.php使用google recaptcha在postLogin方法。Laravel不承認特質

有一個特點

<?php 

namespace App\Traits; 

use Illuminate\Support\Facades\Input; 
use ReCaptcha\ReCaptcha; 

trait CaptchaTrait { 
    public function captchaCheck() 
    { 
     ... 
    } 
} 

和我AuthenticatesUsers.php開始與

<?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; 
... 
} 

在登錄頁面,我得到這個錯誤

FatalErrorException in AuthenticatesUsers.php line 13: Trait 
'App\Traits\CaptchaTrait' not found 

不明白爲什麼。在PhpStorm進口類時CaptchaTrait自動導入應用程序\特徵\ CaptchaTraitAuthenticatesUsers.php

我缺少什麼?

+0

你的特質文件在哪裏? – jiboulex

+0

app/App/Traits/CaptchaTrait.php – Caco

+1

但是,修改'vendor'文件是個不好的習慣。 –

回答

3

查看您的composer.json文件以獲取有關App命名空間的更多信息。這是一個鏈接到應用程序/目錄(PSR-4)。

因此命名空間App \ Traits等同於目錄app/Traits,而不是app/App/Traits。命名空間和目錄必須與您的composer自動加載器中定義的內容相匹配,否則它將不知道如何加載類/特徵/接口。