laravel - 在 Laravel auth 中,该路由不支持 POST 方法。支持的方法:GET、HEAD
问题描述
我正在尝试在我的 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');
通过阅读这个解决方案,我编辑了我的路线: -
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}"
用户.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。
解决方案
检查 app/Notifications/VerifyEmail 文件。
此通知使用用户模型的主键,默认模型假设“id”列是模型实例的主键。但是在您的模型中,主键是“uuid”,因此您必须将此行添加到您的模型中。
protected $primaryKey="uuid";
推荐阅读
- java - Java SQL 语句关闭
- azure - Azure 订阅/服务主体在创建后检索 rbac 角色的 app_id 和应用密码
- typescript - 如何在 Typescript 中引发类型错误
- python - 未找到参数:tessedit_create_txt
- windows - 使用 Packer 构建 Windows EC2 映像
- apache-kafka - KStream 通过非键值与 GlobalKTable 连接
- machine-learning - 如何用 SVM 处理多类分类?
- python - Python烧瓶删除请求
- vba - 如何在 VBA 中将参数从文本传递到宏
- javascript - 如何从 c#(Razor Syntax) 中的对象列表转到 javascript 中的数组或对象?