laravellaravel-5eloquent

Wildcard-like syntax in an eloquent Where clause?


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.'%')