PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 2, 2022

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

 January 02, 2022     eloquent, laravel, laravel-5, laravel-eloquent     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing