我有一个表,数据已经传递给它,并且正在存储。我想将它分成表格的不同列以使其易于阅读。当我使用时:<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 关注
- 118 浏览
添加回答
举报
0/150
提交
取消