[Vuejs]-Convert Laravel signed route that pushes data to signed route with Vue component that pulls data

0๐Ÿ‘

I have a Laravel signed Url page, which allows me to share a page with guest users.

Here is what I propose

As per docs, there is a method to verify signed URLs.

You could give the user the URL and when the user loads the page (component mounted) send an AJAX request with the signature and return all the necessary place data from the controller so that you can inject it into the page with Vue.

JS

Axios.get(`/share/place/25?signature=${your_signed_url_signature}`)
.then(response=>{
  const data = response.data; //your "place" data
  //..do something with it
})

PHP

use Illuminate\Http\Request;

Route::get('/share/place/{id}', function (Request $request) {
  if (! $request->hasValidSignature()) {
      // not authorised
      abort(401);
  }
  //Gather all necessary place data and return it

  return response()->json([
    'data' => $data 
  ])

})->name('unsubscribe');

If the signature supplied to the AJAX request is incorrect or expired, the PHP method will return a 401 status response, so be sure to add extra code to handle that in your vue code.

Leave a comment