gpt4 book ai didi

php - Laravel 5.1 中未找到类错误

转载 作者:行者123 更新时间:2023-12-02 03:05:12 25 4
gpt4 key购买 nike

大家好,我正在尝试学习 PHP 框架以及 OOP,并且我正在使用 Laravel 5.1 LTS。

我的 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;

}

}

我的错误消息未找到类“Models\Verification”来自此处的这段代码

// pass everything to the model here 
$setVerification = new Verification();
$setVerification->setVerificationCode($data['email'], $data['confirmation_code']);

这在我的初学者看来是正确的,但显然是错误的。

这是我的 Verification 类,它具有 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 中提供以下内容

use App\Http\Controllers\Verification;

而不是

use App\Verification;

如果我们指定 use App\Verification ,它将检查是否存在名为 Verification 的模型。

关于php - Laravel 5.1 中未找到类错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36145561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com