Get Count In Mysql Query In Laravel
I wants to select the count of votes got for each items.Following query works fine but there is a problem if there is no vote for an item then that item is not showing in result.I actually wants details of each items and votes.If there is no vote for an item it should be shown count zero. How can i achieve it?
DB::table('wonders') ->leftjoin('vote','votes.wonderId','=','wonders.id') ->select('wonders.id','wonders.title',DB::raw('count(votes.vote) as votes')) ->get();
DB::table('wonders') ->leftjoin('vote','votes.wonderId','=','wonders.id') ->select('wonders.id','wonders.title',DB::raw('ifnull(count(votes.vote),0) as votes')) ->groupBy('wonders.id') ->get();
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?