为了账号安全,请及时绑定邮箱和手机立即绑定

我的迁移文件在运行“php artisan migrate”时出现错误

我的迁移文件在运行“php artisan migrate”时出现错误

PHP
达令说 2023-04-02 14:54:28
我得到的错误是“Illuminate\Database\QueryException:SQLSTATE[42S22]:未找到列:1054 ‘where 子句’中的未知列‘key’(SQL:从其中选择 *!=admin_settings空key限制 1)”因为函数在app/Providers/AppServiceProvider.php public function boot()    {        if (Schema::hasTable('admin_settings')) {            $google_analytics_details = AdminSetting::where('key','!=','null')->first();        }else {            $google_analytics_details = '';        }                View::share('google_analytics_details', $google_analytics_details);    }当我评论引导功能的代码时,它就成功迁移了。我正在寻找此视图共享的替代方案。谁能帮我??我的迁移文件内容:<?phpuse Illuminate\Database\Migrations\Migration;use Illuminate\Database\Schema\Blueprint;use Illuminate\Support\Facades\Schema;class UpdateAdminSettingsTable extends Migration{    /**     * Run the migrations.     *     * @return void     */    public function up()    {        //         Schema::table('admin_settings', function (Blueprint $table) {            $table->dropColumn('google_analytics_code');        });        Schema::table('admin_settings', function (Blueprint $table) {            $table->longText('key')->nullable()->after('id');            $table->longText('value')->nullable()->after('key');        });    }    /**     * Reverse the migrations.     *     * @return void     */    public function down()    {        //         Schema::table('admin_settings', function (Blueprint $table) {        });    }}
查看完整描述

1 回答

?
ABOUTYOU

TA贡献1812条经验 获得超5个赞

如果您想将变量共享到一个视图(可以加载或扩展到其他视图,例如layout.app),您可以指定视图名称,如下例所示

简单的例子:

View::composer('view-name', function ($view) {

             $view->with('key', 'value');

        });

或者如果您在所有视图中都需要它,您可以*像这样用作视图名称


View::composer('*', function ($view) {

             $view->with('key', 'value');

        });

另一种解决问题的方法

您的迁移问题也可以在共享视图之前通过条件解决


 public function boot()

    {

        if ( !app()->runningInConsole() ){

             // your code here

        }

    }


查看完整回答
反对 回复 2023-04-02
  • 1 回答
  • 0 关注
  • 106 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信