Entwickler gefundenSpalte nicht :) in Laravel polymorphe Beziehung
ich eine Beziehung gemacht (many-to-many polymorphe) in Laravel
zwischen:
- Benutzer
- Kleidung , Schuhe, ... ect (jedes ist ein Modell für sich)
Hinweis: kann der Benutzer Favorit irgendeine er (Kleidung oder Schuhe ... etc)
Benutzermodell mögen:
class User extends Authenticatable
{
public function clothes()
{
return $this->morphToMany('Etrade\clothes\Clothes' ,'favoritable')
->withTimestamps('created_at','updated_at');
}
}
Kleidung Modell:
class Clothes extends Model
{
// relationship with user
public function user()
{
return $this->morphToMany('Etrade\Users\User' ,'favoritable')
->withTimestamps('created_at','updated_at');
}
}
bevorzugtes Modell:
class Favriable extends Model
{
protected $table = 'favoritables';
public function favoritable()
{
return $this->morphTo();
}
}
das Abrufen von Daten Beziehung mit:
- alle Benutzer für bestimmte Kleidung erhalten:
$clo= Etrade\clothes\Clothes::find(35);
$clo->user; // fetch the relation
=> Illuminate\Database\Eloquent\Collection {#760
all: [
Etrade\Users\User {#761
id: 4,
name: "Reta Paucek",
email: "[email protected]",
gender: 0,
mobile: "",
city_id: 0,
active: 0,
friend_status: 1,
created_at: "2016-12-26 18:53:51",
updated_at: "2016-12-26 18:53:51",
pivot: Illuminate\Database\Eloquent\Relations\MorphPivot {#213
favoritable_id: 35,
user_id: 4,
created_at: "2016-12-30 03:34:58",
updated_at: "2016-12-30 03:34:58",
},
},
],
}
- erhalten alle Kleider für bestimmte Benutzer:
$user = Etrade\Users\User::find(4);
$user->clothes; // fetch the relationship
Erste Fehler:
Column not found: 1054 Unknown column 'favoritables.clothes_id' in 'field list' (SQL: select
`clothes`.*, `favoritables`.`favoritable_id` as `pivot_favoritable_id`, `favoritables`.`clothes_id` as `pivot_clothes_id`, `favoritables`.`created_at` as `pivo
t_created_at`, `favoritables`.`updated_at` as `pivot_updated_at` from `clothes` inner join `favoritables` on `clothes`.`id` = `favoritables`.`clothes_id` where
`favoritables`.`favoritable_id` = 4 and `favoritables`.`favoritable_type` = Etrade\Users\User)'
Meine Frage: wie diesen Fehler zu beheben ,,, die Beziehung der Arbeit in einer Richtung nicht für beide ??