Laravel
- 1 ответ
- 0 вопросов
1
Вклад в тег
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
/**
* Get the phone record associated with the user.
*/
public function phone()
{
return $this->hasOne('App\Phone');
}
}
$users = (new User())->newQuery()->get();
foreach($users as $user){
$phone = $user->phone;
}
$users = (new User())->newQuery()->with('phone')->get();
$users->load('phone');