vendredi 17 février 2017

Can not get relationship data using Laravel Eloquent ORM

I am working with Laravel 5.4. I am using Eloquent ORM. I have created to table as Countries and States. Both are dislpay as below :

Countries Table :

enter image description here

States Table :

enter image description here

Now, I have wrote two method to set relationship between States and Countries table.

Country Model :

public function states()
{
    return $this->hasMany('App\Models\Masters\State')->select('*');
}

State Model :

public function country()
{
    return $this->belongsTo('App\Models\Masters\Country')->select('name as country_name');
}

Now, I am going to create edit functionality so I can not get country name.

I have written query as

$state = State::with('country')->find($id);
return Response($state);

Here, I got only state data and country data as null.

So what should I have to change to get state as well country data?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2m2RjnX
via IFTTT

Aucun commentaire:

Enregistrer un commentaire