I have complex query builder to get all image from images relation with images_tags table
$tags = [1, 2, 3];
$items = ImagesTable::with(['images_tags' => function ($query) use ($tags) {
$tags = $query->select('image_id', ImageTag::raw('count(tag_id) as total'))
->whereIn('tag_id', $tags)
->groupBy('image_id')
->having(['total', 3])
->get();
return $tags;
}])->get();
And two table
(images)-(images_tags) 1-n
images (
id int
title varchar(255)
)
images_tags (
id int
image_id,
tag_id int
constraints fk foreign key('image_id') on images('id')
)
But i get error
ErrorException in Grammar.php line 58:
strtolower() expects parameter 1 to be string, object given
And i found this line code cause error
ImageTag::raw('count(tag_id) as total')
And i don't know why is this?