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;
Using Eloquent you can perform a search like this: User::query() ->where('name', 'LIKE', "%{$searchTerm}%") ->orWhere('email', 'LIKE', "%{$searchTerm}%") ->get();
You can use the LIKE MySQL keyword and % wildcard character with where clause. In laravel, using whereLike() eloquent method, you can implement laravel where like search query, laravel where like multiple columns and laravel collection with where like.
Eloquent is an object relational mapper (ORM) that is included by default within the Laravel framework. An ORM is software that facilitates handling database records by representing data as objects, working as a layer of abstraction on top of the database engine used to store an application's data.
Use like
:
->where('post_type', 'like', '%'.$string.'%')
Try this
$query->where($field, 'like', $input . '%');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With