consultas complejas elocuentes
$user = User::find("user_id")->with('clicks')->get();
$clicks = $user->clicks()->count();
Powerful Penguin
$user = User::find("user_id")->with('clicks')->get();
$clicks = $user->clicks()->count();
public function clicksCount(){
return $this->hasOne('App\Models\Eloquent\Click')
->select(DB:raw("user_id, COUNT(*) count"))
->groupBy("user_id");
}
public function getClicksCountAttribute(){
return $this->clicksCount->count();
}