Laravel 5 blade show if localhost

Problem

I want to show my google analytics UA code based on localhost (local development) or live server. I think there are a few options such as storing the UA code in the .env file but i’d prefer to just have an if else statement in the blade file for the head layout.

Solution

laravel blade if localhost (i use an alias local. but you can change that to localhost if you want).
      @if (Request::is(‘local/*’))
        ga(‘create’, ‘UA-788xxx55-4’, ‘auto’); //live
      @else
        ga(‘create’, ‘UA-788xxx55-5’, ‘auto’); //localhost
      @endif
laravel blade if localhost
Fullstack4u.com shares web development tips for full stack web technologies and is helping share the passion to web developers worldwide.

Leave a Reply

Your email address will not be published. Required fields are marked *