Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

FounderStartup's avatar

Script not working on laravel site

I am having this error in the CONSOLE of my home page. The code needs to run a script to display projects in the dropdown. Strangely its working fine on the local but not on production server.

[blocked] The page at https://demo.MyDomain.com/ was not allowed to display insecure content from http://127.0.0.1:8000/search-projects.

0 likes
31 replies
Sinnbeck's avatar

Check you env file. Sounds like it has a bad url on production

1 like
FounderStartup's avatar

@Sinnbeck Env

APP_NAME=BBB APP_ENV=production APP_KEY=base64:OX8Bp7c3zT9ipqgT14ybv6Lb0eVDu+lDiPDT37pqQvw= APP_DEBUG=true APP_URL=https://demo.BBB.com

GOOGLE_MAPS_API_KEY=

LOG_CHANNEL=stack LOG_LEVEL=debug

DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=xxxx DB_USERNAME=xxxx DB_PASSWORD=xxxx

RAZOR_KEY=xxxx RAZOR_SECRET=xxxx BROADCAST_DRIVER=log CACHE_DRIVER=file QUEUE_CONNECTION=sync SESSION_DRIVER=database SESSION_LIFETIME=525600

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379

MAIL_MAILER=smtp MAIL_HOST=smtp.mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=xxxx MAIL_PASSWORD=xxxx MAIL_ENCRYPTION=tls MAIL_FROM_ADDRESS=xxxx MAIL_FROM_NAME="${APP_NAME}"

QUEUE_CONNECTION=database

AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION=us-east-1 AWS_BUCKET=

PUSHER_APP_ID= PUSHER_APP_KEY= PUSHER_APP_SECRET= PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

DEBUGBAR_ENABLED = TRUE

Sinnbeck's avatar

@FounderStartup try ADDING (Remember to clear cache with php artisan config:clear)

ASSET_URL=https://demo.BBB.com 
1 like
FounderStartup's avatar

@Sinnbeck

controller

    // Home page project search bar
	public function SearchProjects(Request $request){

		$request->validate(["search" => "required"]);
		$item = $request->search;
        $projects = Projects::with('city','locality','builder')
            ->whereHas('city', function ($query) {$query->where('status', 1);})
            ->where('project_name','LIKE',"%$item%")
            ->select('project_name','project_image','project_city','id','project_builder','slug')
            ->limit(5)
            ->get();

		return view('frontend.searchbar.search_projects',compact('projects'));

	} // end method
FounderStartup's avatar

@Sinnbeck Route

// Home page project search bar route
Route::post('/search-projects', [IndexController::class, 'SearchProjects']);
Route::post('/search-cities', [IndexController::class, 'SearchCities']);
Route::post('/search-builders', [IndexController::class, 'SearchBuilders']);
FounderStartup's avatar

@Sinnbeck

View for search bar :


<section>
    <div class="banner-1 cover-image sptb-2 sptb-tab bg-background2" data-image-src="{{asset('frontend/assets/images/banners/banner1.jpg')}}">
        <div class="header-text mb-0">
            <div class="container">
                <div class="row">
                    <div class="card-body br-2">
                        <div class="text-center text-white">
                            <h1 class="mb-1">Your Property, Our Priority.</h1>
                            <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.</p>
                        </div>
                        <div class="search-area  search-area3 search-area2 search-background bg-transparent">
                            {{-- <form method="post" action="{{ route('projects.search') }}">
                                @csrf --}}
                            <div class="form row no-gutters ">
                                <div class="form-group  col-xl-3 col-lg-3 col-md-12 mb-0 bg-white">
                                    <input type="text" class="search-field form-control input-lg br-tr-md-0 br-br-md-0" onfocus="search_result_show()" onblur="search_result_hide()" id="search" name="search" placeholder="Enter building/society name">
                                    {{-- <input type="text" class="form-control input-lg br-tr-md-0 br-br-md-0" id="text4" placeholder="Enter a building/society name"> --}}
                                </div>
                                <div class="form-group  col-xl-3 col-lg-3 col-md-12 mb-0 bg-white">
                                    <input type="text" class="search-field form-control input-lg br-tr-md-0 br-br-md-0" onfocus="search_result_show2()" onblur="search_result_hide2()" id="search2" name="search2" placeholder="Enter city name">
                                        {{-- <span><i class="fa fa-map-marker location-gps mr-1"></i> </span> --}}
                                </div>
                                <div class="form-group  col-xl-3 col-lg-3 col-md-12 mb-0 bg-white">
                                    <input type="text" class="search-field form-control input-lg br-tr-md-0 br-br-md-0" onfocus="search_result_show3()" onblur="search_result_hide3()" id="search3" name="search3" placeholder="Enter builder name">

                                    {{-- <input type="text" class="form-control input-lg br-md-0" id="text5" placeholder="Enter Builder"> --}}
                                        {{-- <span><i class="fa fa-map-marker location-gps mr-1"></i> </span> --}}
                                </div>
                                <div class="col-xl-3 col-lg-3 col-md-12 mb-0">
                                    <button class="btn btn-lg btn-block btn-primary br-tl-md-0 br-bl-md-0 search-button" type="submit">Search Societies</button>

                                    {{-- <a href="#" class="btn btn-lg btn-block btn-primary br-tl-md-0 br-bl-md-0">Search Here</a> --}}
                                </div>
                            </div>
                            {{-- </form> --}}
                        </div>
                        <div id="searchProducts"></div>
                        <div id="searchProducts3"></div>
                        <div id="searchProducts2"></div>
                    </div>
                </div>
            </div>
        </div><!-- /header-text -->
    </div>
</section>

FounderStartup's avatar

@Sinnbeck



<style>

    .search-area3{
      position: relative;
    }
      #searchProducts3{
        position: absolute;
        top: 100%;
        left: 49%;
        width: 40%;
        /* background: #ffffff; */
        z-index: 999;
        border-radius: 8px;
        margin-top: 5px;
      }
</style>


<script>
      function search_result_hide3(){
        $("#searchProducts3").slideUp();
      }
       function search_result_show3(){
          $("#searchProducts3").slideDown();
      }
</script>


<style>
    .search-area2{
      position: relative;
    }
      #searchProducts2{
        position: absolute;
        top: 100%;
        left: 25%;
        width: 35%;
        /* background: #ffffff; */
        z-index: 999;
        border-radius: 8px;
        margin-top: 5px;
      }
</style>


<script>
      function search_result_hide2(){
        $("#searchProducts2").slideUp();
      }
       function search_result_show2(){
          $("#searchProducts2").slideDown();
      }
</script>



<style>
    .search-area{
      position: relative;
    }
      #searchProducts{
        position: absolute;
        top: 100%;
        left: 2%;
        width: 50%;
        /* background: #ffffff; */
        z-index: 999;
        border-radius: 8px;
        margin-top: 5px;
      }
</style>


<script>
      function search_result_hide(){
        $("#searchProducts").slideUp();
      }
       function search_result_show(){
          $("#searchProducts").slideDown();
      }
</script>

Sinnbeck's avatar

@FounderStartup I am not getting that error. I get alot of others though. Maybe try clearning cache for the page (ctrl+shift+delete). Dont delete cookies!

1 like
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@FounderStartup Ah managed to recreate the error. The url is in the file named "projectsearch.js"

const site_url = "http://127.0.0.1:8000/";
//should be
const site_url = document.location.origin;
1 like
Sinnbeck's avatar

@FounderStartup I found it by

  1. F12 to open dev tools
  2. ctrl+shift+f and search for 127.0.0.1
  3. Check them one at a time untill I found one
1 like
FounderStartup's avatar

@Sinnbeck I actually replaced with actual url of the site and it worked. :) It was a marathon for me. Thanks for your constant support. You are an amazing developer :).

FounderStartup's avatar

@Sinnbeck Its working now. Thanks a ton. The only concern is that its not working soon local now. So what should I do so it works on both local as well as production ? I have used the absolute url of the domain.

Sinnbeck's avatar

@FounderStartup Never use that. Ive show you how to get the url from the address bar above document.location.origin

1 like
Sinnbeck's avatar

@FounderStartup Remember to add a bit more details to leave out guessing. You get a new error? On local? Or production?

1 like
FounderStartup's avatar

@Sinnbeck OK

when I use :

const site_url = document.location.origin;

It does not work on local or production.

Please or to participate in this conversation.