title: Laravel Email Verification for Vue SPA
body: <p>How can I implement Laravel's Email Verification on a Vue SPA with Vue Router?</p>
  
  <p>So far I have tried to handle email verification by altering the VerificationController verify and resend methods. I then created a new notification and added API routes for the Verification.</p>
  
  <p>When the verification link is generated and sent to user's email, the verification url is something like:</p>
  
  <p><a href="https://foobar.test/email/verify/1?expires=1565276056&amp;signature=b15ccd7d6198bdcf81eea4f5cb441efe8eb2d6d5b57a1ce0b1171e685613d917" rel="noreferrer">https://foobar.test/email/verify/1?expires=1565276056&amp;signature=b15ccd7d6198bdcf81eea4f5cb441efe8eb2d6d5b57a1ce0b1171e685613d917</a></p>
  
  <p>When the link is clicked, it opens up a page but it does nothing on the backend as the @verify api route is not hit.</p>
  
  <p>Any suggestions?</p>
  
  <p>VerificationController.php</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers\Auth;
  
  use App\User;
  use Illuminate\Http\Request;
  
  use App\Http\Controllers\Controller;
  use Illuminate\Foundation\Auth\VerifiesEmails;
  use Illuminate\Validation\ValidationException;
  
  
  class VerificationController extends Controller
  {
      /*
      |--------------------------------------------------------------------------
      | Email Verification Controller
      |--------------------------------------------------------------------------
      |
      | This controller is responsible for handling email verification for any
      | user that recently registered with the application. Emails may also
      | be re-sent if the user didn't receive the original email message.
      |
      */
  
      use VerifiesEmails;
  
      /**
       * Where to redirect users after verification.
       *
       * @var string
       */
      protected $redirectTo = '/home';
  
      /**
       * Create a new controller instance.
       *
       * @return void
       */
      public function __construct()
      {
          $this-&gt;middleware('auth:api');
          $this-&gt;middleware('signed')-&gt;only('verify');
          $this-&gt;middleware('throttle:600,1')-&gt;only('verify', 'resend');
      }
  
      /**
       * Show the email verification notice.
       *
       */
      public function show()
      {
          //
      }
  
      /**
       * Mark the authenticated user's email address as verified.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return \Illuminate\Http\Response
       */
      public function verify(Request $request)
      {
        $userID = $request[‘id’];
        $user = User::findOrFail($userID);
        $user-&gt;email_verified_at = date("Y-m-d g:i:s");
        $user-&gt;save();
  
        return response()-&gt;json('Email verified!');
      }
  
      /**
       * Resend the email verification notification.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return \Illuminate\Http\Response
       */
      public function resend(Request $request)
      {
          if ($request-&gt;user()-&gt;hasVerifiedEmail()) {
              return response()-&gt;json('The email is already verified.', 422);
          }
  
          $request-&gt;user()-&gt;sendEmailVerificationNotification();
  
          return response()-&gt;json('We have e-mailed your verification link!');
      }
  
  
  }
  </code></pre>
  
  <p>VerifyEmail.php</p>
  
  <pre><code>&lt;?php
  
  namespace App\Notifications;
  
  use Illuminate\Notifications\Notification;
  
  
  use Illuminate\Support\Facades\URL;
  use Carbon\Carbon;
  
  
  use Illuminate\Auth\Notifications\VerifyEmail as VerifyEmailBase;
  
  
  class VerifyEmail extends VerifyEmailBase
  {
  
      /**
       * Get the verification URL for the given notifiable.
       *
       * @param  mixed  $notifiable
       * @return string
       */
      protected function verificationUrl($notifiable)
      {
        return URL::temporarySignedRoute(
        ‘verification.verify’, Carbon::now()-&gt;addMinutes(60), [‘id’ =&gt; $notifiable-&gt;getKey()]
        );
  
      }
  }
  </code></pre>
  
  <p>Api.php</p>
  
  <pre><code>Route::get('email/verify/{id}', 'Auth\VerificationController@verify')-&gt;name('verification.verify');
  Route::get('email/resend', 'Auth\VerificationController@resend')-&gt;name('verification.resend');
  </code></pre>