Laravel - When to use ->get()

后端 未结 5 1914
悲哀的现实
悲哀的现实 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:24

    • For find(n), you retrieve a row based on the primary key which is 'n'.
    • For first(), you retrieve the first row among all rows that fit the where clauses.
    • For get(), you retrieve all the rows that fit the where clauses. (Please note that loops are required to access all the rows or you will get some errors).

提交回复
热议问题