Last active
March 14, 2019 20:18
-
-
Save TiagoSilvaPereira/80d4949ab83093a2b7ad429d1fefe269 to your computer and use it in GitHub Desktop.
KISS aplicado ao código
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Código complexo gerado pela falta de simplicidade na estrutura | |
$labels = DB::table('labelables') | |
->select(['labelables.*', 'labels.id as label_id', 'labels.slug', 'labels.title']) | |
->join('labels', 'labels.id', 'labelables.label_id') | |
->where('labels.title', 'like', '%'.$search.'%') | |
->where('labelables.labelable_type', $request->labelable_type) | |
->whereRaw('(SELECT count(id) | |
FROM labelables AS count_labelables | |
WHERE count_labelables.labelable_type = labelables.labelable_type | |
AND count_labelables.project_id = labelables.project_id | |
AND count_labelables.labelable_id = ? | |
AND count_labelables.label_id = labelables.label_id | |
AND count_labelables.color = labelables.color | |
AND count_labelables.deleted_at IS NULL) = 0', $request->labelable_id) | |
->groupBy(['labels.title', 'labelables.color']) | |
->orderBy('labelables.updated_at', 'ASC') | |
->limit($limit); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment