在Laravel auth中,此路由不支持POST方法.支持的方法:GET、HEAD



我正试图在我的laravel 8项目中设置电子邮件验证,我已经使用auth命令在我的项目中设置了mu身份验证。我得到的错误是:-

缺少[Route:verification.verify][URI:email/verify/{id}]所需的参数。

这是我的家庭控制器:-

public function __construct()
{
$this->middleware(['auth', 'verified']);
}

这是我的web.php:-(我确实有更多的路线(

use IlluminateSupportFacadesRoute;
use AppHttpControllersHomeController;
use AppHttpControllersConfessionsController;
use AppHttpControllersFriendsController;

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');

通过阅读这个解决方案,我编辑了我的路线如下:-

use AppHttpControllersAuthVerificationController;```
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 AppModels;
use IlluminateContractsAuthMustVerifyEmail;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateFoundationAuthUser as Authenticatable;
use IlluminateNotificationsNotifiable;
use AppModelsConcernsUsesUuid;
use AppModelsConfession;
use WebpatserUuidUuid;
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。

检查app/Notifications/VerifyEmail文件。

该通知使用用户模型的主键,并且默认模型假设";id";列是模型实例的主键。但在您的模型中,主键是";uuid";所以你必须把这一行添加到你的模型中。

protected $primaryKey="uuid";

相关内容

最新更新