Laravel-datatables: Force https connection

Created on 21 Feb 2020  路  6Comments  路  Source: yajra/laravel-datatables

Summary of problem or feature request


I updated my version today and it have an issue on https connection it was worked before but after update this error showing to me

Mixed Content: The page at 'https://' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://'. This request has been blocked; the content must be served over HTTPS.

I'm using yajra datatables class that generated using > php artisan datatables:make ClassDatatable

Code snippet of problem

System details

  • Operating System
  • PHP Version 7.4
  • Laravel Version 6.x
  • Laravel-Datatables Version
    "yajra/laravel-datatables": "^1.5",
    "yajra/laravel-datatables-oracle": "^9.7",
https

Most helpful comment

If you are already forcing https, add this $this->app['request']->server->set('HTTPS', true); to the register method.

<?php

namespace App\Providers;

use Illuminate\Routing\UrlGenerator;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app['request']->server->set('HTTPS', true);
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot(UrlGenerator $url)
    {
        if (config('app.force_https')) {
            $url->forceScheme('https');
        }
    }
}

All 6 comments

I think this is an issue on the URL helper and can be fixed using URL::forceScheme('https') as per SO post https://stackoverflow.com/questions/24426423/laravel-generate-secure-https-url-from-route?

I already force https and it was working in https before this update
Now its not working after update

Thanks, it's working

If you are already forcing https, add this $this->app['request']->server->set('HTTPS', true); to the register method.

<?php

namespace App\Providers;

use Illuminate\Routing\UrlGenerator;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app['request']->server->set('HTTPS', true);
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot(UrlGenerator $url)
    {
        if (config('app.force_https')) {
            $url->forceScheme('https');
        }
    }
}

Thanks, @devfelipereis It's working

Was this page helpful?
0 / 5 - 0 ratings

Related issues

baig772 picture baig772  路  14Comments

Arkhas picture Arkhas  路  15Comments

Yahav picture Yahav  路  16Comments

FaZeRs picture FaZeRs  路  18Comments

AbuHamdah picture AbuHamdah  路  33Comments