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.
Can you post full stack trace error to investigate the issue?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community