【问题标题】:My laravel 5.6 project is opening on localhost but not on php artisan serve cmd我的 laravel 5.6 项目在 localhost 上打开,但不在 php artisan serve cmd 上打开
【发布时间】:2021-06-24 08:15:25
【问题描述】:

我从朋友的电脑上复制了 laravel 5.6 项目。它在他的电脑上运行良好,但在我的电脑上却不行。 当我在 cmd 中运行 php artisan serve 命令时,它给了我 cmd 中的错误(附截图)。cmd screenshot

它可以在 localhost/tailorMS 上很好地打开:localhost screenshot

laravel 7 和 8 的其他项目在 cmd 上打开没有任何问题。 我的 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);
    }
}


【问题讨论】:

  • 可能与PHP版本有关,诸如此类?只是为了版本的差异
  • 我有 php 7.4.3 版本,但我不知道它是在哪个版本中制作的
  • 只需删除这些行。或者为 CLI 调用添加一个例外

标签: php laravel laravel-7 laravel-8 php-5.6


【解决方案1】:

更改条件以检测是否为 CLI 调用,因此无需检查端口

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

【讨论】:

  • 成功了。谢谢@N69S。但它只加载 html,而不是引导 css 样式。在localhost/tailorMS 上,它会加载完整的 CSS 样式
  • npm install && npm run dev 加载资产
猜你喜欢
  • 2019-08-01
  • 2021-03-31
  • 2020-07-10
  • 2018-01-31
  • 2016-07-25
  • 2019-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多