我有一個表,數據已經傳遞給它,并且正在存儲。我想將它分成表格的不同列以使其易于閱讀。當我使用時:<td>{{$message->Content['text']}}</td>我收到錯誤:Trying to access array offset on value of type null (View: VIEWSDIRECTORY)。這是似乎正在拉動的轉儲,我正在嘗試返回,"text":"SPOCK"因為我可以為每個部分重復該過程,即鍵入: { #attributes: array:11 [ "id" => "b5ef7556-c208-40b0-8bfa-1358bf482cd0" "method" => "sms" "msisdn" => 6422 "direction" => "mo" "type" => "suggestion" "status" => "received" "content" => "{"senderPhoneNumber":"+6422","messageId":"Ms5ppMnxRHTw26gFSRwbsvAA","sendTime":"2020-06-05T03:20:58.506749Z","suggestionResponse":{"postbackData":"49da99a5-bc85-4efd-9587-54c335e7f329","text":"SPOCK","type":"REPLY"}}" "suggestion_id" => "49da99a5-bc85-4efd-9587-54c335e7f329" "created_at" => 1591327269 "updated_at" => 1591327269 "deleted_at" => null ]我的控制器: { $message = Message::find($id); return view($message->direction . $message->type, compact('message')); }}刀刃: <thead> <tr> <th scope="col">MESSAGE ID</th> <th scope="col">MESSAGE</th> </tr> </thead> <tbody> <tr> <td style='font-size:14px'>{{$message->id}}</td> <td>{{$message->Content['text']}}</td>我的消息模型: /** * Get the suggestions for this message. */ public function suggestions() { return $this->hasMany(Suggestion::class); } public function getContentAttribute($value) { return json_decode($value); }
1 回答

慕的地8271018
TA貢獻1796條經驗 獲得超4個贊
看起來(問題中不清楚)您發布的 JSON 是模型content
字段的值Message
,對嗎?text
如果是這樣,您正試圖在其位于屬性內部時直接訪問Response
。
所以你的觀點應該是這樣的:
<td>{{$message->content->Response->text}}</td>
- 1 回答
- 0 關注
- 151 瀏覽
添加回答
舉報
0/150
提交
取消