Search code examples
phplaravellaravel-7laravel-8php-5.6

My laravel 5.6 project is opening on localhost but not on php artisan serve cmd


I have copied laravel 5.6 project from friend's PC. It is running well on his PC but not on mine. When I run php artisan serve command in cmd it gives me the error in cmd(screenshot attached).cmd screenshot

It opens on localhost/tailorMS well:localhost screenshot

Other projects of laravel versions 7 and 8 open without any problem on cmd. my AppServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\View;
use DB;
use Illuminate\Support\Facades\URL;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    public function boot()
    {
        if( (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) {
            URL::forceScheme('https');
        }
        //setting language
        if(isset($_COOKIE['language'])) {
            \App::setLocale($_COOKIE['language']);
        } else {
            \App::setLocale('en');
        }
        //get general setting value        
        $general_setting = DB::table('general_settings')->latest()->first();
        View::share('general_setting', $general_setting);
        config(['staff_access' => $general_setting->staff_access, 'date_format' => $general_setting->date_format, 'currency' => $general_setting->currency, 'currency_position' => $general_setting->currency_position]);
        
        $alert_product = DB::table('products')->where('is_active', true)->whereColumn('alert_quantity', '>', 'qty')->count();
        View::share('alert_product', $alert_product);
        Schema::defaultStringLength(191);
    }
}



Solution

  • Change the condition to detect if it's a CLI call, so no need to check for port

    if(strpos(php_sapi_name(), 'cli') === false && ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443)) {
        URL::forceScheme('https');
    }