【问题标题】:Symfony\Component\Debug\Exception\FatalThrowableError : syntax error, unexpected 'public' (T_PUBLIC)Symfony\Component\Debug\Exception\FatalThrowableError :语法错误,意外的“公共”(T_PUBLIC)
【发布时间】:2020-03-22 21:05:16
【问题描述】:

您好,我遇到了问题PHP artisan migrate does not migrate all tables 遵循了该程序,但我遇到了另一个错误。


    λ php artisan migrate

       Symfony\Component\Debug\Exception\FatalThrowableError  : syntax error, unexpected 'public' (T_PUBLIC), expecting end of file

      at C:\laragon\www\blog\app\Providers\AppServiceProvider.php:34
        30| }
        31|
        32| use Illuminate\Support\Facades\Schema;
        33|
      > 34| public function boot()
        35| {
        36|     Schema::defaultStringLength(191);
        37| }
        38|

      Exception trace:

      1   Composer\Autoload\includeFile("C:\laragon\www\blog\vendor\composer/../../app/Providers/AppServiceProvider.php")
          C:\laragon\www\blog\vendor\composer\ClassLoader.php:322

      2   Composer\Autoload\ClassLoader::loadClass("App\Providers\AppServiceProvider")
          [internal]:0

      Please use the argument -v to see more details.

AppServiceProvider.php 文件已更改,我什至尝试将新类放在顶部。并且错误是相同的,除非它在不同的行上检测到。




    <?php

    namespace App\Providers;





    use Illuminate\Support\ServiceProvider;

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

        /**
         * Bootstrap any application services.
         *
         * @return void
         */
        public function boot()
        {
            //


        }
    }

    use Illuminate\Support\Facades\Schema;

    public function boot()
    {
        Schema::defaultStringLength(191);
    }

【问题讨论】:

  • 您是否将该代码粘贴到课堂之外?您可以粘贴整个AppServiceProvider(在您的问题中)吗?
  • 发布迁移代码
  • 好吧,然后将代码发布到您的AppServiceProvider.php 课程中。您可能应该将use 声明进一步提高。
  • 是的。我什至尝试重新启动 Laragon,所以我使用该架构代码运行 php artisan serve 但我得到了相同的错误消息,只是为了找出问题所在

标签: php laravel migration


【解决方案1】:

您的app/Providers/AppServiceProvider.php 应该与此类似

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider {

    public function boot(){
        \Schema::defaultStringLength(191);
    }

    public function register()
    {
        //
    }

}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-12-06
  • 2022-01-21
  • 1970-01-01
  • 2017-03-08
  • 2019-08-02
  • 2020-05-15
  • 2018-08-18
  • 1970-01-01
相关资源
最近更新 更多