Jimmy
Jimmy

Reputation: 3

How to use route name in laravel from api route

I've been using ajax to access the google api, the route I've been using is from the API route in laravel. The problem is that I cant use the route name in the ajax because when using the api route there is a prefix 'api'.

Upvotes: 0

Views: 898

Answers (1)

Amit Senjaliya
Amit Senjaliya

Reputation: 2945

You can able to access the route name directly inside ajax as a URL.

API Route with name method:

Route::get('/user/profile', [UserProfileController::class, 'show'])->name('profile');

Where profile is your route name. Inside ajax call in the laravel blade file.

url:"{{ route('profile') }}",

Upvotes: 1

Related Questions