0

I have protected laravel api routes now I want to access each route using ajax after the user is Logged In. The Login is api is working and access token is also generated, now I dont know how to use that access token to access different APIs in on different pages of the application.

Route::group(['middleware' => ['auth:api']], function () {

 Route::get('/user', function (Request $request) {
     return $request->user();
 });

});

I want to access user route using jquery ajax

$(document).ready(function(){
      $.ajax({
            type: "GET",
            url: "/api/user",
            data:({
                _token: "{{ csrf_token() }}",

            }),
            success: function(result)
            {
              console.log('Success');
            }
         });
       });
HAMZA HUMMAM
  • 309
  • 1
  • 2
  • 9

0 Answers0