php - Perform advanced where clause Eloquent -



php - Perform advanced where clause Eloquent -

i know how perform 'advanced where'. didn't find in documentation explain want.. there. (cf: http://laravel.com/docs/4.2/queries#advanced-wheres).

post::wherehas('international_post_en', function($q) { $q->where('is_published', 1); })->wherehas('categories', function($q) { $q->where('name', 'test-one'); })->orwherehas('subcategories', function($q) { $q->where('name', 'test-two'); })->with('categories', 'subtags') ->get();

my query this:

select * `posts` `posts`.`deleted_at` null , (select count(*) `international_posts_en` `international_posts_en`.`posts_id` = `posts`.`id` , `is_published` = ?) >= 1 , (select count(*) `categories` inner bring together `posts_has_categories` on `categories`.`id` = `posts_has_categories`.`categories_id` `posts_has_categories`.`posts_id` = `posts`.`id` , `name` = ?) >= 1 or (select count(*) `subcategories` inner bring together `posts_has_subcategories` on `subcategories`.`id` = `posts_has_subcategories`.`subcategories_id` `posts_has_subcategories`.`posts_id` = `posts`.`id` , `name_en` = ?) >= 1

but want query this:

select * `posts` `posts`.`deleted_at` null , (select count(*) `international_posts_en` `international_posts_en`.`posts_id` = `posts`.`id` , `is_published` = ?) >= 1 , [(](select count(*) `categories` inner bring together `posts_has_categories` on `categories`.`id` = `posts_has_categories`.`categories_id` `posts_has_categories`.`posts_id` = `posts`.`id` , `name` = ?) >= 1 or (select count(*) `subcategories` inner bring together `posts_has_subcategories` on `subcategories`.`id` = `posts_has_subcategories`.`subcategories_id` `posts_has_subcategories`.`posts_id` = `posts`.`id` , `name_en` = ?) >= 1[)]

(sorry not readable)

you can see changes within brackets. so, want wherehas , orwherehas clause grouped within parenthesis.

is possible laravel query builder or should create handmade query?

thank in advance.

post::wherehas('international_post_en', function($q) { $q->where('is_published', 1); })->where(function ($q) { $q->wherehas('categories', function($q) { $q->where('name', 'test-one'); })->orwherehas('subcategories', function($q) { $q->where('name', 'test-two'); }); })->with('categories', 'subtags')->get();

in fact first illustration on page linked. illustration pretty inaccurate, since wouldn't grouping and wheres against or where, other way around..

php laravel eloquent

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -