Laravel 7/6 Eloquent orWhereIn Example

10-Apr-2023

.

Admin

Today, i would like to show you laravel eloquent orwherein example. This post will give you simple example of orwherein laravel eloquent. if you have question about laravel eloquent orwherein then i will give simple example with solution i would like to share with you laravel eloquent where with orwherein example. You just need to some step to done laravel orwherein example .

Example :


SQL Query :

select * from `users` where `type` = ? or `id` in (?, ?)

Laravel Query :

public function index()

{

$users = DB::table('users')

->where('type', 2)

->orWhereIn('id',[3, 4])

->get();

dd($users);

}

Output :

#items: array:3 [?

0 => {#324 ?

+"id": 1

+"name": "admin"

+"email": "admin@gmail.com"

+"type": 2

+"remember_token": null

+"created_at": "2019-12-28 00:00:00"

+"updated_at": null

}

1 => {#327 ?

+"id": 3

+"name": "mehul"

+"email": "bagadamehul@gmail.com"

+"type": 1

+"remember_token": null

+"created_at": "2019-12-27 00:00:00"

+"updated_at": null

}

2 => {#323 ?

+"id": 4

+"name": "jd"

+"email": "aatmaninfotech@gmail.com"

+"type": 1

+"remember_token": null

+"created_at": "2020-02-04 00:00:00"

+"updated_at": null

}

]

It will help you....

#Laravel 7

#Laravel

#Laravel 6