2017-09-20 80 views
0

我有一個設置爲JSON值的輸入項目,因爲我想以後得到控制這個價值得到JSON的價值,但我只是得到[對象,對象]laravel如何從輸入

的JSON是:

[{ 
    "title": "G30 BMW 530d is Victoria Police's new patrol car - 80 units to join fleet by end-2018, all with 'police pack'", 
    "url": "https://paultan.org/2017/09/20/g30-bmw-530d-is-victoria-police-new-patrol-car/", 
    "thumbnail": "https://s1.paultan.org/image/2017/09/VP_HWP_Bmw_530D_Front_side.jpg", 
    "source": "Paul Tan's Automotive News", 
    "source_url": "https://paultan.org/2017/09/20/g30-bmw-530d-is-victoria-police-new-patrol-car/", 
    "date_published": "2017-09-20", 
    "provider": "Event Registry", 
    "provider_url": "http://eventregistry.org" 
}, { 
    "title": "Opel Astra GSi Spied Nearly Naked", 
    "url": "http://gmauthority.com/blog/2017/09/opel-astra-gsi-spied-nearly-naked/", 
    "thumbnail": "http://gmauthority.com/blog/wp-content/uploads/2017/07/Opel-GSi-Teaser-1024x771.jpg", 
    "source": "GM Authority", 
    "source_url": "http://gmauthority.com/blog/2017/09/opel-astra-gsi-spied-nearly-naked/", 
    "date_published": "2017-09-19", 
    "provider": "Event Registry", 
    "provider_url": "http://eventregistry.org" 
}] 

Vuejs

<div v-for="article in articles_sortByDate" v-bind:key="article.id"> 
    <input type="checkbox" 
      :value="article" 
      v-model="checkedArtcles" 
      name='checkedArtcles'> 
</div> 

現在,如果我嘗試從控制器該值與

dd($request->input('checkedArtcles')); 

//this results in [Object, object] 

也試過:

dd(json_decode($request->input('checkedArtcles'))); 

//this return NUll 
+0

請提供工作示例。片段中的現場演示? – C2486

回答

0

在JavaScript邏輯(在這種情況下VUE)解析您的JSON字符串,然後追加選擇的值,然後在C ontroller,你可以嘗試訪問$request->input('checkedArtcles')或dd。

+0

我認爲,問題是$ request-> input('')正在將json更改爲字符串,從而獲取對象,對象。我已經試過您的解決方案,並在返回字符串錯誤調用一個成員函數指定者() – Hina

+0

所以這意味着$請求 - >輸入(「checkedArtcles」)是一個字符串,你能告訴我在VUE生成的源代碼,按ctrl +你的頁面上顯示選擇,可能是因爲它的值已經與值'對象'字符串。 –

+0

你可能就在這裏是我得到的源文件 [object Object],[object Object],[object Object]「 – Hina