laravel eloquent where and code example
Example 1: laravel eloquent get first
$user = App\User::where('id',$id)->first();
$userId = App\User::where(...)->pluck('id');
Example 2: eloquent where in
$users = DB::table('users')->whereIn('id', array(1, 2, 3))->get()
Example 3: where () laravel Eloquent
$user = User::where("estado","=",1)->find(10);
Example 4: laravel where multiple conditions on single colmn
$data = Users::where('type',1)
->where(function($query) {
return $query->whereDate('updated_at','!=', Carbon::today())
->orWhere('updated_at',null);
})
->get();
Example 5: laravel where
$users = DB::table('users')
->whereMonth('created_at', '12')
->get();
Example 6: eloquent first
$user = User::where('mobile', Input::get('mobile'))->get();
if (!$user->isEmpty()){
$firstUser = $user->first()
}