laravel-口才-从返回数组中获取特定值

问题描述 投票:1回答:1

我正在关注代码:

$gallery->photos->first()

此返回:

{"id":3,"gallery_id":1,"filename":"IMG_3700.png","filesize":4229181,"delete":0,"created_at":"2020-03-28T09:56:31.000000Z","updated_at":"2020-03-28T09:56:31.000000Z"}

我需要访问文件名。我尝试了一些操作,但没有一个起作用:

$gallery->photos->first('filename')
$gallery->photos->first()->get('filename')
$gallery->photos->first()['filename']
$gallery->photos->first()->filename

我如何访问返回的文件名?

谢谢

arrays laravel eloquent
1个回答
0
投票

确保您没有从控制器返回json对象。

© www.soinside.com 2019 - 2024. All rights reserved.