I have three models, the one that connects the other two is a pivot table but holds some extra columns.
My pivot:
class PropertyTenant extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'property_tenant';
public $timestamps = false;
public function tenant() {
return $this->belongsTo('App\Models\User');
}
public function property() {
return $this->belongsTo('App\Models\Property');
}
}
User:
class User extends Authenticatable
{
public function propertiesOccupied() {
return $this->hasMany('App\Models\PropertyTenant');
}
}
Property:
class Property extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'properties';
public function tenants() {
return $this->hasMany('App\Models\PropertyTenant');
}
}
I don't think that belongsTo
is the correct thing to use in my pivot table. What should I be doing instead?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Z25UgH
via IFTTT
Aucun commentaire:
Enregistrer un commentaire