Skip to content
Advertisement

How to execute an IF url or route contains … function with LARAVEL 5

I use Laravel 5 for one of my projets and after hours spend I’m asking for little help!!

I need to execute a Script (Google Gtag) if the user is on this exact url :

https://website.com/offer/payment/success/[dynamic]

or/and comes from:

https://checkout.stripe.com/pay/[dynamic]

I tried this without succes:

@if(!Request::is('offer/payment/success/*'))
....
@endif

Does someone can help me ?

Advertisement

Answer

You can use str_contains() for this purpose.The str_contains() function checks whether the string (parameter #1) contains the second string.

@if(str_contains(url()->current(), 'offer/payment/success/'))
     ........
@endif

As per official documentation details of url()->current().

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement