Where and like condition with laravel aggregates operators

Friends, in where condition and like operator both are very important to fetch the data in any Laravel query and it is very useful not only in laravel but also in PHP.

In today’s tutorial we will learn about the non conditional and like operator and its use with mathematical operations:

$users = DB::table('users')
->where('votes', '=', 100)
->where('age', '>', 35)
->get();
$users = DB::table('users')
->where('votes', '>=', 100)
->get();
$users = DB::table('users')
->where('votes', '<>', 100)
->get();
$users = DB::table('users')
->where('name', 'like', 'T%')
->get();
$users = DB::table('users')->where([
  ['status', '=', '1'],
  ['subscribed', '<>', '1'],
])->get();
$users = DB::table('users')
->where('votes', '>', 100)
->orWhere('name', 'John')
->get();
$users = DB::table('users')
->where('votes', '>', 100)
->orWhere(function(Builder$query) {
  $query->where('name', 'Abigail')
  ->where('votes', '>', 50);
})
->get();
$products = DB::table('products')
->whereNot(function(Builder$query) {
$query->where('clearance', true)
->orWhere('price', '<', 10);
})
->get();
$users = DB::table('users')
->whereBetween('votes', [1, 100])
->get();
$users = DB::table('users')
->whereNotBetween('votes', [1, 100])
->get();
$patients = DB::table('patients')
->whereBetweenColumns('weight', ['minimum_allowed_weight', 'maximum_allowed_weight'])
->get();
$patients = DB::table('patients')
->whereNotBetweenColumns('weight', ['minimum_allowed_weight', 'maximum_allowed_weight'])
->get();
$users = DB::table('users')
->whereIn('id', [1, 2, 3])
->get();
$users = DB::table('users')
->whereNotIn('id', [1, 2, 3])
->get();
$activeUsers = DB::table('users')->select('id')->where('is_active', 1);
$users = DB::table('comments')
->whereIn('user_id', $activeUsers)
->get();
$users = DB::table('users')
->whereNull('updated_at')
->get();
$users = DB::table('users')
->whereNotNull('updated_at')
->get();
$users = DB::table('users')
->whereColumn('first_name', 'last_name')
->get();
$users = DB::table('users')
->whereColumn('updated_at', '>', 'created_at')
->get();
$users = DB::table('users')
->whereColumn([
  ['first_name', '=', 'last_name'],
  ['updated_at', '>', 'created_at'],
])->get();

Leave a Reply