i wanna create activity feed in laravel4, so i've done this with polymorphic relations where Feed model has item() function, here it's:
class Feed extends \Eloquent
{
protected $table = 'feed';
public function item()
{
return $this->morphTo();
}
}
Then i added other relations for child models:
class UserStatus extends \Eloquent
{
protected $table = 'user_status';
public function feed()
{
return $this->morphMany('Feed', 'item');
}
}
class Photo extends \Eloquent
{
protected $table = 'photo';
public function feed()
{
return $this->morphMany('Feed', 'item');
}
}
But when i query activities of user it shows: Class name must be a valid object or a string
Here's my query in User model:
class User extends \Eloquent
{
public function activities()
{
return $this->hasMany('Feed', 'user_id')->with('item')->get();
}
}
How can I get activity list (parent polymorphic model Feed) for user?
From the docs...
Polymorphic relations allow a model to belong to more than one other model, on a single association. For example, you might have a photo model that belongs to either a staff model or an order model.
This allows a child object (eg. a photo or comment) to belong to more than one type of parent object. I think you're trying to do the opposite - a single parent with multiple types of children.