John Davidson

php - where and orWhere issue for same column data in laravel

0 comments
Message:


My table is look like






































id locale language_name
1 bn Bengali
2 en English
3 hi Hindi
4 ar Arabic
5 ja_jp Japanese


My Answer:
In Laravel, the `where` and `orWhere` methods are used to add conditions to a query. If you want to query the same column with different values using `where` and `orWhere`, you can do so by chaining the methods together.

For example, if you want to retrieve records where the `locale_language_name` column is either 'en' or 'ar', you can do the following:

php
$records = DB::table('your_table_name')
->where('locale_language_name', 'en')
->orWhere('locale_language_name', 'ar')
->get();


This will retrieve records where the `locale_language_name` column is either 'en' or 'ar'.

If you want to retrieve records where the `locale_language_name` column is 'en' and 'ar', you can do the following:

php
$records = DB::table('your_table_name')
->where('locale_language_name', 'en')
->where('locale_language_name', 'ar')
->get();


This will retrieve records where the `locale_language_name` column is both 'en' and 'ar', which is not possible. In this case, you should use the `whereIn` method instead:

php
$records = DB::table('your_table_name')
->whereIn('locale_language_name', ['en', 'ar'])
->get();


This will retrieve records where the `locale_language_name` column is either 'en' or 'ar'.

Rate this post

5 of 5 based on 3546 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us