Search Comma Separated values using FIND_IN_SET in Laravel Query Builder

Search Comma Separated values using FIND_IN_SET in Laravel Query Builder

In this post, I will tell you how to search comma separated value in Laravel Query Builder using MySQL find_in_set() method.

Using find_in_set() method, you can find the position of a string within a comma separated value.

Syntax
FIND_IN_SET(needle,haystack);

Ok, Let's have a table which stores the article with the tags and you need to find out value from comma separated tags.

articles table

article table

Now if you need to find out the articles that tagged into "php", you can use the "FIND_IN_SET" method in following way :

SELECT 
    title
FROM
    articles
WHERE
    FIND_IN_SET('php', tags);

FIND_IN_SET method is predefine method of MySQL.

In Laravel, You will use whereRaw() method to write your own raw SQL queries.

So you can use "find_in_set" method with whereRaw() in Laravel.

  1. $data = \DB::table("articles")
  2.      ->select("title")
  3.      ->whereRaw("find_in_set('php',tags)")
  4.      ->get();
Output :
Collection {#169 ▼
  #items: array:1 [▼
    0 => {#170 ▼
      +"title": "PHP Basic"
    }
  ]
}

Phone: (+91) 8800417876
Noida, 201301
ataşehir escort maltepe escort bostancı escort kadıköy escort maltepe escort ataşehir escort tuzla escort pendik escort ümraniye escort kartal escort
pendik escort
izmir escort izmir escort izmir escort izmir escort denizli escort antalya escort antalya escort antalya escort izmir escort izmir escort izmir escort izmir escort izmir escort
hatay escort nevsehir escort nigde escort kirikkale escort batman escort osmaniye escort kirklareli escort tokat escort rize escort adiyaman escort gumushane escort batman escort
porno izle
cialis satış cialis fiyat cialis 20 mg cialis 100 mg cialis 5 mg fiyat
sohbet okey oyna
ankara escort marmaris escort bursa escort mersin escort antalya escort izmir escort samsun escort bodrum escort çeşme escort kuşadası escort adana escort eskişehir escort gaziantep escort esenyurt escort pendik escort tuzla escort fatih escort ümraniye escort mecidiyeköy escort kartal escort bahçelievler escort bahçeşehir escort ataşehir escort bakırköy escort nişantaşı escort avcılar escort büyükçekmece escort kurtkoy escort konya escort beşiktaş escort taksim escort beylikdüzü escort malatya escort sakarya escort şişli escort maltepe escort kadıköy escort ataköy escort bostancı escort şirinevler escort bağcılar escort üsküdar escort etiler escort başaksehir escort ortaköy escort kağıthane escort sultangazi escort halkalı escort çekmeköy escort şaşkınbakkal escort mamak escort sincan escort keçiören escort çankaya escort beypazarı escort akyurt escort pursaklar escort kahramankazan escort göztepe escort alsancak escort bornova escort buca escort karabaglar escort karşıyaka escort konak escort narlıdere escort izmit escort başiskele escort kandira escort körfez escort karamürsel escort dilovası escort gölcük escort gebze escort kocaeli escort kayseri escort elazığ escort denizli escort diyarbakir escort adana escort ankara escort izmir escort antalya escort gaziantep escort kayseri escort konya escort mersin escort denizli escort kocaeli escort diyarbakır escort