0

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.

Kakashi Hatake
  • 133
  • 1
  • 9
  • How do you call(request) your endpoint? – Onur Demir Jan 01 '21 at 22:34
  • @OnurDemir I'm sorry I didn't understand your question, I have just used [this](https://www.techiediaries.com/laravel/laravel-7-6-email-verification-tutorial-example/) tutorial to get email verification. Can you please explain. I am just a beginner. – Kakashi Hatake Jan 01 '21 at 22:40
  • Are you clicking to Verify Email Button? or Are you calling the endpoint manually something like PostMan? – Onur Demir Jan 01 '21 at 22:45
  • 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 Jan 01 '21 at 22:48
  • Maybe you can remove verify routes you put manually and use this like in the tutorial. ```Auth::routes(['verify' => true]);``` – Onur Demir Jan 01 '21 at 22:52
  • And you still didnt tell me exactly when do you get this error? – Onur Demir Jan 01 '21 at 22:53
  • @OnurDemir As I hit the register button This error pops up. The user does get registered in the database but the verification email is not sent – Kakashi Hatake Jan 01 '21 at 22:55
  • As I have mentioned in the question I have tried putting it manually but still got the same error. – Kakashi Hatake Jan 01 '21 at 22:58

1 Answers1

0

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";
anas omush
  • 322
  • 1
  • 7
  • Now it doses not show any error as I hit register but doesn't send any email as well and when I hit ``click here to request another`` it shows me this error ``The POST method is not supported for this route. Supported methods: GET, HEAD.`` – Kakashi Hatake Jan 02 '21 at 05:50
  • This is a different issue? about email you have to set mail trap config on your .env file second one its normal you are try to reload page pages current url called post method and when you try to refresh call get request – anas omush Jan 02 '21 at 08:31
  • @anas omush Mailtrap is for demo purpose, I want to use this for production that's why I have linked my gmail account – Anonymous Chatbox Jan 02 '21 at 09:15
  • So you have to check smtp configuration – anas omush Jan 02 '21 at 10:40
  • @anasomush I have also shared my config in the question above, I don't see anything wrong in it, if you do please let me know – Kakashi Hatake Jan 04 '21 at 17:40