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

Monday, January 24, 2022

[FIXED] Query only records that match specific substring - Laravel 5

 January 24, 2022     laravel, laravel-5, mysql, php, sql     No comments   

Issue

I would like to query my visitors records from my visitors table that has the the OS substring of bot.

enter image description here

As you can see, there are 3 of 8 records listed here right now. I just want to grab those 3.

I tried look in this documentation. I didn't really find what I am looking to do there, unless I missed it.

$visitors = Visitor::orderBy('created_at', 'desc')
        ->where('os',substr('bot'))<----- NEED help here 
        ->get();

Update

I believe my question is not a duplicate of this proposed duplicate.


Solution

Did you try with 'LIKE'

$visitors = Visitor::orderBy('created_at', 'desc')
->where('os', 'like', '%bot%') //<----- Match any word containing ...bot.. at any place
->get();

Using a variable

$visitors = Visitor::orderBy('created_at', 'desc')
->where('os', 'like', '%'. $bot .'%') //<----- Match the searched variable
->get();


Answered By - EddyTheDove
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

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