0
votes

I am trying to set-up a email verification in my laravel 8 project, I have used auth commmand to setup mu authentication in my project. The error that I am getting is:-

Missing required parameters for [Route: verification.verify] [URI: email/verify/{id}].

Here's my HomeController:-

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

Here's my web.php:- (I do have more routes)

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

By reading this solution I edited my routes to this:-

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

but still I got the same error.

Here's My .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);
 });
  }
}

UPDATE:- I have added protected $primaryKey="uuid"; in my User Model and now as I hit register I don't get any error as well as no email but as I hit click here to request another I get this error:-

The POST method is not supported for this route. Supported methods: GET, HEAD.

1
How do you call(request) your endpoint?Onur Demir
@OnurDemir I'm sorry I didn't understand your question, I have just used this tutorial to get email verification. Can you please explain. I am just a beginner.Kakashi Hatake
Are you clicking to Verify Email Button? or Are you calling the endpoint manually something like PostMan?Onur Demir
It automatically send a verification email as the user hits register, I have updated my env file as well in the question and i will be updating my user model.Kakashi Hatake
Maybe you can remove verify routes you put manually and use this like in the tutorial. Auth::routes(['verify' => true]);Onur Demir

1 Answers

0
votes

Check app/Notifications/VerifyEmail file.

This notification use primary key of User Model and by default model suppose "id" column is the primary key of your model instance. but in your model primary key is "uuid" so you have to add this line into your model.

protected $primaryKey="uuid";