0

I am using : dd(User::find(1)->get()); on a table that has 4994 rows, and the above query returns all the rows. But when I do :

User::where('id',1)->with('groups')->get()

, I get the right row(just one)

User table has a column called id, which is primary key.

I am using Laravel Framework version 5.1.31 (LTS)

Could anybody tell me what the problem is ?

harveyslash
  • 5,906
  • 12
  • 58
  • 111

2 Answers2

8

you don't need to attach get() with find() method. find is the shortest and simplest method to return single record without attaching get().

just do this, you will get only single record.

dd(User::find(1)); 
Qazi
  • 5,015
  • 8
  • 42
  • 62
0

Since the find() function will always use the primary key for the table, the need for get() is not necessary. Because you can't narrow your selection down using primary key and that's why it will always just try to get that record and return it.

Source: https://stackoverflow.com/a/13698488/4807414

Community
  • 1
  • 1
VijayRana
  • 953
  • 1
  • 13
  • 38