phones:id , id_user,number
users:id,username,email,password.
Los modelos
Users
Código PHP:
<?php
class Users extends Eloquent {
protected $table = 'users';
protected $fillable = array('username', 'email', 'password');
/**1-1***/
public function phone()
{
return $this->hasOne('Phone','id');
}
<?php
class Phone extends Eloquent {
protected $table = 'phones';
protected $fillable = array('id_user', 'number');
public function users()
{
return $this->belongsTo('Users');
}
}
Código PHP:
public function unoauno()
{
$user = Users::find(38)->get();
$phone = $user->number();
return $phone;
}
Call to undefined method Illuminate\Database\Eloquent\Collection::number()