亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel 將數組分成表字段

Laravel 將數組分成表字段

PHP
揚帆大魚 2023-04-28 16:45:27
我有一個表,數據已經傳遞給它,并且正在存儲。我想將它分成表格的不同列以使其易于閱讀。當我使用時:<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>


查看完整回答
反對 回復 2023-04-28
  • 1 回答
  • 0 關注
  • 151 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號