Reputation: 1
hasOne(Address::class); } public function city() { return $this->belongsTo(City::class); } public function goal() { return $this->belongsTo(Goal::class); } public function type() { return $this->belongsTo(Type::class); } public function neighborhoods() { return $this->belongsToMany(Neighborhood::class)->withTimestamps(); } public function pictures() { return $this->hasMany(Picture::class); } }
Upvotes: 0
Views: 637
Reputation: 405
Welcome to our community you have mistaken with the name of the relation change neighborhoods to neighborhood without s
public function neighborhood()
{
return $this->belongsToMany(Neighborhood::class)->withTimestamps();
}
Upvotes: 0
Reputation: 1
For a Many To Many relationship you have to make sure that you have already created the pivot table in your case your pivot name table would be: property_neighborhood. then you have to edit the neighborhoods() relationship as following:
public function neighborhoods()
{
return $this->belongsToMany(Neighborhood::class , 'property_neighborhood', 'neighborhood_id', 'property_id')->withTimestamps();
}
Upvotes: 0