Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.3 query builder: 'NOTLIKE' not working

Tags:

laravel

I have a table that has a column named version that has four rows containing values

|Version |
|--------|
|5.3     | 
|5.2     | 
|5.3     | 
|5.2,5.3 |

I want to get rows that's values are not like 5.2 I mean, I want to get the first and third rows not second and fourth rows.

I used Eloquent Model 'Menu' to make the query as below.

$query = Menu:where('version', 'NOTLIKE', '%5.2%')->get();
$numberRows = count($query);

$numberRows equals to 0.

Am I in the right way? Or, is there any other way to do this? I need help.

like image 890
Md. Harun Or Rashid Avatar asked Dec 05 '16 04:12

Md. Harun Or Rashid


People also ask

How do I use whereBetween in Laravel?

The whereBetween() method is a query builder chained alongside other Laravel query builders used to fetch data from the database. The whereBetween() method queries the database table to fetch rows of records from the database within a range of values.

How does Laravel query builder work?

In Laravel the database query builder provides an easy interface to create and run database queries. It can be used to perform all the database operations in your application, from basic DB Connection, CRUD, Aggregates, etc. and it works on all supported database systems like a champ.

What is the difference between eloquent and query builder in Laravel?

Eloquent ORM is best suited working with fewer data in a particular table. On the other side, query builder takes less time to handle numerous data whether in one or more tables faster than Eloquent ORM. In my case, I use ELoquent ORM in an application with tables that will hold less than 17500 entries.


1 Answers

Change NOTLIKE to NOT LIKE

Correct code:

$query = Menu::where('version', 'NOT LIKE', '%5.2%')->get();
$numberRows = count($query);
like image 154
Parth Vora Avatar answered Oct 15 '22 15:10

Parth Vora