0

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();
John Lobo
  • 14,355
  • 2
  • 10
  • 20
  • can you show route for tht url and error is activation($code).you havent passed param in method – John Lobo Jul 08 '21 at 15:31
  • 4
    This is the first line of `activation()`: `$user = User::where('code',$code)->first();`... You don't define `$code` anywhere before that. Is there something unclear about your error message? – Tim Lewis Jul 08 '21 at 15:32
  • Thank you @TimLewis. Your solution fixed my problem –  Jul 08 '21 at 16:15

0 Answers0