I have a trait which can be assigned to multiple models, this is called Visitorable. I have set up a polymorphic relation so that I can have different entities that are Visitorable. (All visitable does is log user information, IP Address etc for that entity).
I currently have a method in my trait which returns unique count:
public function visitorCount($unique = true)
{
$query = $this->visitors();
if($unique === false)
return $query->count();
return $query->get()->unique('ip_address')->count();
}
But I would rather not have to call this method in my controller each time, ideally, I would like it to be eager loaded and automatically added to every row.
How could I achieve this? At the moment, attempting to eager load this gives me an error about Eager loading an integer?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2igm5Ni
via IFTTT
Aucun commentaire:
Enregistrer un commentaire