Provider (AppServiceProvider)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
use Illuminate\Support\Facades\App; public function boot() { $env = App::environment(); if($env == 'local' || $env == 'test'){ define('USE_HTTPS', false); }else{ define('USE_HTTPS', true); } if(USE_HTTPS == true){ \URL::forceScheme('https'); $base_url = secure_url('/'); }else{ $base_url = url('/'); } define('BASE_URL', $base_url . '/'); define('ASSETS_FRONT', $base_url . '/assets/front/'); define('ASSETS_ADMIN', $base_url . '/assets/admin/'); } |
HTML:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<script> var base_url = '{{BASE_URL}}'; $(document).ready(function() { $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content') } }); @if(USE_HTTPS == true) if (location.protocol != 'https:') { location.href = 'https:' + window.location.href.substring(window.location.protocol.length); } @endif }); </script> |