2017-10-13 60 views
0

我升級到laravel 5.5和Voyager 1.0,並在流浪盒上使用mysql。無法重新創建DataRow在Laravel Voyager中的關係

我想在data_rows表上爲用戶和商店之間的關係添加一個條目。我可以使用Voyager的gui創建條目。

creating relationship gui view of relationship 當我所有這些值複製到我的播種機

$dataRow = $this->dataRow($storeDataType, 'store_belongsto_user_relationship'); 
if (!$dataRow->exists) { 
    $dataRow->fill([ 
     'type'   => 'relationship', 
     'display_name' => 'Manager', 
     'required'  => 0, 
     'browse'  => 1, 
     'read'   => 1, 
     'edit'   => 1, 
     'add'   => 1, 
     'delete'  => 1, 
     'details'  => '{"model":"App\\User","table":"users","type":"belongsTo","column":"manager_id","key":"id","label":"email","pivot_table":"ad_store","pivot":"0"}', 
     'order'  => 20, 
    ])->save(); 
} 

和運行我的數據庫遷移與我自定義的播種機,如果我重新加載/database/stores/bread/edit網頁,其中創建相應的表項 enter image description here 我得到一個錯誤,用於訪問在這一行觸發的非對象的屬性。

<?php if($relationshipDetails->type == 'belongsTo'): ?><?php echo e('flexed'); ?><?php endif; ?> 

這意味着存儲在詳細信息字段中的json無效。我不明白這是怎麼回事,但當我逐字地將它複製到我的播種機上時。是否還有其他一些條目添加到另一個表或緩存中,我的播種器沒有考慮到?我爬過了數據庫條目,找不到任何明顯的東西。

編輯

添加在參考了問題這條線,我發現這是與問題相關的

@php $relationshipDetails = json_decode($relationship['details']); @endphp 

回答

0

因此,這是有點白癡的我的一部分。我的播種機插入一個我定義的字符串; "model":"App\\User",我認爲這足以讓\字符進入db。它是什麼。問題在於我添加到問題的最後一行。

json_decode($relationship['details']) 

當這個函數被調用時,它會嘗試從數據庫中的字符串中創建一個json對象。不幸的是,它並沒有成功創建json對象,因爲播種機將字符串"model":"App\User"插入到數據庫中。

爲了解決這個問題,我改變字符串聲明在播種到

"model":"App\\\\User"

其插入到我的數據庫爲

"model":"App\\User"

,當它被傳遞json_decode變得

"model": "App\User"

讓這成爲轉義角色的重要課程。