Support the ongoing development of Laravel.io →
Blade Artisan Authentication

I'm trying to send Email Activation link to newly registered users to activate the account/email, but I keep on getting this error:-Trying to Access Array offset on Value of Type null. I have been using the same method for a long time now. I can't seem to figure out what's going on. Below is my code.

`<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request; use App\Models\User; use App\Models\VerifyUser; use Illuminate\Support\Facades\Mail; use App\Mail\AccountVerification; use Illuminate\Support\Str; use Carbon\Carbon; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash;

class AuthController extends Controller { public function Register(Request $request){ $request->validate([ 'name' => 'required|string', 'email' => 'required|email|unique:users', 'password' => 'required|confirmed|min:6' ]);

       $user = new User();
       $user->name = $request->name;
       $user->email = $request->email;
       $user->password = Hash::make($request->password);
       $user->save();

       $users = new VerifyUser();
       $users->token = Str::random(60);
       $users->user_id = $user->id;
       $users->save();

       if(Mail::to($user->email)->send(new AccountVerification($user))){
         return back()->with('success','Account created. Please check email to activate your account.');
       }else{
        return back()->with('fail','We could not register your account.');
       }
}

} `

I need help.

nanakumi75 liked this thread

1

Can you post full stack trace error to investigate the issue?

Last updated by @mohitsingla46 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.