Reputation: 3244
I have an ajax function which will use an URL.
ajaxMyFunction('{{route('myroute.route1')}}', function (result) { //do stuff });
I want to call the route only if it exists in my dynamic route list because Laravel throws exception if myroute.route1
doesn't exist yet.
Is there a way to check route before render it inside blade, like when we check views ?
@if(View::exists('myroute.route1'))
I tried, Route::has('myroute.route1')
but it doesn't work as well.
Thanx for your help guys ;)
Upvotes: 1
Views: 2311
Reputation: 163978
As I explained in my Laravel best practices repo, you shouldn't mix JS and Blade syntax. To make it work, do something like this on the backend:
let route = {{ Route::has('myroute.route1') ? route('myroute.route1') : 'false' }}
And then in JS, you will be able to do something like this:
if (route) {
ajaxMyFunction(route, ....);
}
Upvotes: 2