Php 在Laravel 5.1中未找到类错误
嘿,伙计们,我正在尝试学习PHP框架以及OOP,我正在使用Laravel5.1LTS 我的Php 在Laravel 5.1中未找到类错误,php,laravel,Php,Laravel,嘿,伙计们,我正在尝试学习PHP框架以及OOP,我正在使用Laravel5.1LTS 我的AuthController <?php namespace App\Http\Controllers\Auth; use App\Verification; use Mail; use App\User; use Validator; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\ThrottlesLogi
AuthController
<?php
namespace App\Http\Controllers\Auth;
use App\Verification;
use Mail;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
private $redirectTo = '/home';
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}
protected function create(array $data){
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
// generate our UUID confirmation_code
mt_srand((double)microtime()*15000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$uuid = substr($charid, 0, 8)
.substr($charid, 8, 4)
.substr($charid,12, 4)
.substr($charid,16, 4)
.substr($charid,20,12);
$data['confirmation_code'] = $uuid;
// pass everything to the model here
$setVerification = new Verification();
$setVerification->setVerificationCode($data['email'], $data['confirmation_code']);
// send email for confirmation
Mail::send('email.test', $data, function ($m) use ($data){
$m->from('test@test.com', 'Your Application');
$m->to($data['email'])->subject('Thanks for register! Dont forget to confirm your email address');
});
return $user;
}
}
这在我的初学者看来是正确的,但显然是错误的
这是我的
验证
类,它具有setVerificationCode方法
<?php
namespace App\Http\Controllers;
use App\User;
use DB;
use App\Http\Controllers\Controller;
class Verification {
/**
* This method will update the confirmation_code column with the UUID
* return boolean
**/
protected function setVerificationCode($email, $uuid) {
$this->email = $email;
$this->uuid = $uuid;
// check to see if $email & $uuid is set
if (isset($email) && isset($uuid)) {
DB::table('users')
->where('email', $email)
->update(['confirmation_code' => $uuid]);
return TRUE;
} else {
return FALSE;
}
}
/**
* This method will validate if the UUID sent in the email matches with the one stored in the DB
* return boolean
**/
protected function verifyConfirmationCode() {
}
}
请在AuthController中提供以下内容 使用App\Http\Controllers\Verification 而不是 使用App\验证
如果我们给使用App\Verification,它将检查是否有任何名为Verification的模型。看起来,您缺少了一些东西,这就用
雄辩的模型扩展了您的模型
use Illuminate\Database\Eloquent\Model;
class Verification extends Model
{
其余的似乎都很好
还可以共享您的验证模型代码
已更新
而不是你的这一行
use App\Verification;
这样做
use App\Models\Verification;
当您为模型创建自定义目录时,最好将其自动加载到composer.json
文件中。在您的“自动加载”部分中添加这一行。照此
"autoload": {
"classmap": [
"database",
"app/Models"
],
然后,在项目repocomposer dump autoload
中运行此命令。此代码似乎不适合控制器。正如Haseena所回答的,问题在于验证的名称空间是App/Http/Controllers而不是App。但是,该名称空间/位置可能不正确。@Devon我对这一切都很陌生,名称空间非常混乱……好吧,现在我找不到Class'App\Http\Controllers\Auth\User'
User是一个模型对吗。?然后将其称为use App\User;我的验证
类是我的模型文件,在我检查代码时,它已经包括App\User
,仅在AuthController中使用用户模型。然后只参考用户模型$User=App\User::create(['name'=>$data['name'],'email'=>$data['email'],'password'=>bcrypt($data['password']),]);你的错误是,你已经在App
目录下创建了Model
目录,我对吗>是的,我已经App>Model>验证了。php
仍然会出错没有找到类“App\Models\Verification”
为什么这么难。。。。。我添加了使用App\Models\Verification
在我的AuthController
中,在你的项目repocomposer dump autoload
中运行此命令。你能给我看一下你的应用程序
目录的屏幕截图吗?还有,你是否用雄辩的模型扩展了你的验证模型。像这样类验证扩展了模型{
"autoload": {
"classmap": [
"database",
"app/Models"
],