Emtiaz Zahid
Emtiaz Zahid

Reputation: 2835

Call laravel naming routes from vue axios

Thinking is that any way to call the routes from route files with their names and get the url to axios in vuejs.

I don't know is it possible or not. If not please suggest me some other way to get the routes which i declared in laravel routes php files. Thanks

Upvotes: 0

Views: 1319

Answers (2)

Nur Uddin
Nur Uddin

Reputation: 1840

    <script>
  window.routes = {
    'users' : '{{ route('users') }}',
    'contact' : '{{ route('contact') }}',
  }

  // You can access it like this
  let route = window.routes.users
</script>

Upvotes: 0

KJ789
KJ789

Reputation: 74

One solution would be to do a Route::getRoutesByName which will return all your routes keyed by the name you provided. You could create a route that returns that route collection.

See the API here: https://laravel.com/api/5.7/Illuminate/Routing/RouteCollection.html#method_getRoutesByName

Upvotes: 1

Related Questions