Попробуйте следующий запрос.
DB::table('table_name')
->select(DB::raw("
sum( case when tag_name = 'happy' then 1 else 0 end) as happy
,sum( case when tag_name = 'sad' then 1 else 0 end) as sad
,sum( case when tag_name = 'angry' then 1 else 0 end) as angry
"), 'date_applied')
->groupBy('date_applied');
Или вы можете использовать прямой запрос
select date_applied
,sum( case when tag_name = 'happy' then 1 else 0 end) as happy
,sum( case when tag_name = 'sad' then 1 else 0 end) as sad
,sum( case when tag_name = 'angry' then 1 else 0 end) as angry
from table
group by date_applied
Для динамических тегов
$tags = Tag::all();
$selectQuery = '';
foreach($tags as $tag){
$selectQuery.="sum( case when tag_name = '".$tag->tag_name."' then 1 else 0 end) as ".$tag->tag_name.",";
}
DB::table('table_name')
->select(DB::raw($selectQuery."date_applied")
->groupBy('date_applied')