Laravel - When to use ->get()

后端 未结 5 1915
悲哀的现实
悲哀的现实 2021-02-07 03:06

I\'m confused as to when ->get() in Laravel...

E.G. DB::table(\'users\')->find(1) doesn\'t need ->get() to retrieve the results, neither

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-07 03:27

    find returns one row from the database and represent it as a fluent / eloquent object. e.g. SELECT * FROM users WHERE id = 3 is equivalent to DB::table('users')->find(3);

    get returns an array of objects. e.g. SELECT * FROM users WHERE created_at > '2014-10-12' is equivalent to DB::table('users')->where('created_at', '>', '2014-10-12')->get() will return an array of objects containing users where the created at field is newer than 4014-10-12.

提交回复
热议问题