dousi9215 2014-08-20 02:19
浏览 429

(Laravel)使用 - > first()时,相关模型查询返回数组而不是对象

Hello, my question is: How can i get an object instead of an array?

for example: when i perform a query like

$checkIn = Check_in::whereHas('user', function($q) use ($user){
   $q->where('id', $user->id); 
})->whereBetween('created_at', array($timetable->entry->startOfDay(), $timetable->entry->endOfDay()))->first();

after that i should be able to do a

echo $checkIn->created_at;

but when i do it i get an errorException

ErrorException
Trying to get property of non-object (View: C:\xampp\htdocs\*\app\views\*\*.blade.php)

but it works when i do a

echo $checkIn['created_at'];

this is annoying, because as an array, i can't use Carbon functions on the dates.

PS: i'm using Laravel 4.1

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 smptlib使用465端口发送邮件失败
    • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
    • ¥15 对于squad数据集的基于bert模型的微调
    • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
    • ¥20 steam下载游戏占用内存
    • ¥15 CST保存项目时失败
    • ¥15 树莓派5怎么用camera module 3啊
    • ¥20 java在应用程序里获取不到扬声器设备
    • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
    • ¥15 Attention is all you need 的代码运行