I have an issue on Laravel CONCAT it doesn't concatenate DB fields. When I checked the returned data it has no fullName
public function getAllPlayers()
{
$data = Player::select(DB::raw('CONCAT(familyName," ",firstName) AS fullName'))
->orderBy('familyName', 'asc')
->join('teams', 'players.primaryClubId', '=', 'teams.clubId')
->select(['players.*', 'teams.teamName', 'teams.teamNickname', 'teams.teamCode'])
->get()
->unique() //remove duplicates
->groupBy(function($item, $key) { //group familyName that starts in same letter
return substr($item['familyName'], 0, 1);
})
->map(function ($subCollection) {
return $subCollection->chunk(4); // put your group size
});
return $data;
}
via PenAndPapers