This is a model
class User {
$table = 'users';
public function item()
{
return $this->hasOne('Item');
}
}
the I make a loop getting the item:
foreach($users as $user)
{
echo $user->item->name;
}
are this user model querying the item each loop?
so if yes will this be the same?
class User {
$table = 'users';
public function item()
{
return Item::where('user_id', '=', $this->id)->first();
}
}
in other words will be the first class method item the same as the second class method item? or is there a difference in performance?
if you are worried about performance, use User::with('item').