I'm making a verification system using laravel8. The system works fine and it allows a user (me) to register. After registration, an email is sent to the user with a verification link. Now, the problem occurs when the user clicks the link. An error "Undefined variable: code". Here's the error and the code enter image description here
ActivateAccountController <?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use App\Mail\ActivateYourAccount;
use Illuminate\Support\Facades\Mail;
class ActivateAccountController extends Controller
{
//
public function activation(){
$user = User::where('code',$code)->first();
$user->code = null;
$user->update([
'active' => 1
]);
auth()->login($user);
return redirect('/')->withSuccess('Connected');
}
public function resendCode($email){
$user = User::where('email',$email)->first();
if($user->active){
return redirect('/');
}
Mail::to($user)->send(new ActivateYourAccount($user->code));
return redirect('/login')->withSuccess('The link was sent to your email address');
}
}
Can anyone assist me with a solution to the problem which appears on line13
$user = User::where('code',$code)->first();