我得到的錯誤是“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
? ? ? ? }
? ? }
- 1 回答
- 0 關注
- 183 瀏覽
添加回答
舉報
0/150
提交
取消