Sunday, January 2, 2022

[FIXED] Wildcard-like syntax in an eloquent Where clause?

Issue

Here is a where clause I have:

->where( 'post_type', '=', 'blog' )

Is there any way to replace 'blog' by a wildcard, so it will match any 'post_type' ?

Full query:

$db = ( new DbSql() )->db()->getConnection();
$postsCount = $db->table( 'posts' )
                          ->where( 'status', '=', 'published' )
                          ->where( 'post_type', '=', 'blog' )
                          ->where( 'alerts', '<', Settings::CONTENT_ALERT_NUMBER_ALLOWANCE )
                         ->count() ?? null;

Solution

Use like:

->where('post_type', 'like', '%'.$string.'%')


Answered By - Alexey Mezenin

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.