【发布时间】:2021-04-08 13:38:03
【问题描述】:
我正在尝试在我的 laravel 8 项目中设置电子邮件验证,我已使用 auth 命令在我的项目中设置 mu 身份验证。 我得到的错误是:-
缺少 [Route: verify.verify] [URI: email/verify/{id}] 的必需参数。
这是我的 HomeController:-
public function __construct()
{
$this->middleware(['auth', 'verified']);
}
这是我的 web.php:-(我确实有更多路线)
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\ConfessionsController;
use App\Http\Controllers\FriendsController;
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', [HomeController::class, 'index'])->name('home');
//Confessions
Route::get('/confessions', [ConfessionsController::class, 'index'])->name('confession.index');
Route::get('/c/c/{id}', [ConfessionsController::class, 'create'])->name('confession.create');
Route::post('/confessions/created/{id}', [ConfessionsController::class, 'post'])->name('confession.store')->middleware('confessions');
Route::get('/confessions/delete/{id}', [ConfessionsController::class, 'destroy'])->name('confession.destroy');
//friends
Route::post('/confessions/add/{id}', [FriendsController::class, 'store'])->name('friend.store')->middleware('friends');
通过阅读this solution,我编辑了我的路线:-
use App\Http\Controllers\Auth\VerificationController;```
Auth::routes();
Route::get('email/verify', [VerificationController::class,'show'])->name('verification.notice');
Route::get('email/verify/{id}', [VerificationController::class,'verify'])->name('verification.verify');
Route::get('email/resend', [VerificationController::class, 'resend'])->name('verification.resend');
但我还是遇到了同样的错误。
这是我的 .env :-
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=MyUsername
MAIL_PASSWORD=MyPassword
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=MyEmailAddress
MAIL_FROM_NAME="${APP_NAME}"
User.php:-
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use App\Models\Concerns\UsesUuid;
use App\Models\Confession;
use Webpatser\Uuid\Uuid;
use Cache;
class User extends Authenticatable implements MustVerifyEmail
{
use HasFactory, Notifiable;
protected $guarded = []; // YOLO
public $incrementing = false;
protected $keyType = 'string';
protected static function boot()
{
parent::boot();
self::creating(function ($user) {
$user->uuid = (string) Uuid::generate(4);
});
}
}
更新:-
我在我的用户模型中添加了protected $primaryKey="uuid";,现在当我点击注册时,我没有收到任何错误以及没有电子邮件,但是当我点击click here to request another时,我收到了这个错误:-
此路由不支持 POST 方法。支持的方法:GET、HEAD。
【问题讨论】:
-
你如何调用(请求)你的端点?
-
@OnurDemir 对不起,我没有理解你的问题,我刚刚使用this 教程来获取电子邮件验证。你能解释一下吗。我只是一个初学者。
-
您是否单击“验证电子邮件”按钮?还是您手动调用端点,例如 PostMan?
-
它会在用户点击注册时自动发送一封验证电子邮件,我已经在问题中更新了我的 env 文件,我将更新我的用户模型。
-
也许您可以删除手动放置的验证路由并像在教程中一样使用它。
Auth::routes(['verify' => true]);
标签: laravel laravel-routing laravel-8 laravel-authentication