vendredi 5 octobre 2018

Eloquent One to Many Relationship in laravel 5.7

I am trying to get data of country name so,

I have two model

1)users model

users:

class Users extends Model
{


    protected $fillable = ['fname','lname','email','password','address','state','city'];


    public function address1()
    {
        return $this->hasOne('App\Addresses');
    }
}

2)addresses model

addresses:

class addresses extends Model
{
    protected $fillable = ['user_id','country'];

    public function user()
    {
        return  $this->belongTo('App\users');
    }
}

now I am getting output - it is an error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'addresses.users_id' in 'where clause' (SQL: select * from addresses where addresses.users_id = 5 and addresses.users_id is not null and addresses.id = 2 limit 1) (View: /Applications/XAMPP/xamppfiles/htdocs/demo/resources/views/profiles.blade.php)

please, solve my problem.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire