Trying to use the setBindings() function due to the raw select:
COUNT(SELECT * FROM `likes` WHERE `ip` = ? AND `article_id` = `articles`.`id`) as has_liked
Full:
$article = Article::selectRaw(
'*, `articles`.`id` as article_id,
`categories`.`name` as category_name,
`categories`.`slug` as category_slug,
`articles`.`slug` as article_slug,
COUNT(`likes`.`id`) as num_likes,
COUNT(SELECT * FROM `likes` WHERE `ip` = ? AND `article_id` = `articles`.`id`) as has_liked
')
->join('categories', 'categories.id', '=', 'articles.category_id')
->join('likes', 'likes.article_id', '=', 'articles.id')
-setBindings([$_SERVER['REMOTE_ADDR']])
->where(['articles.id' => $this->article_id])
->first();
Is there an extra class I need to use or something?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Z4RE7k
via IFTTT
Aucun commentaire:
Enregistrer un commentaire