I apologize in advance if this question is too specific but I am having a hard time choosing the right eloquent relationship between these two models. I have two models, one named "Package" (for example a travel package) and another called "Country". A package can only have one country and a country can have multiple packages. This is my relationship:
class Package extends Model
{
public function country()
{
return $this->belongsTo('App\Country');
}
}
// Country
class Country extends Model
{
public function packages()
{
return $this->hasMany('App\Country');
}
}
Is this the right relationship? When I use the following relationship and I want to get a collection of packages with country information using the code below:
$packages = Package::with('country')->get();
I get NULL
on the countries response. Am I doing anything wrong? Thank you for your assistance.
PS: This is my database structure:
Country:
`id`
`iso_code`
`name`
`phone_code`
Package:
`id`
`title`
`description`
`date_from`
`date_to`
`price`
`country_id`