In this article, We will explain to you how to use where clauses Method in laravel 7(Laravel 7 Where Clauses Methods Example Tutorial). The laravel eloquent provides many types of where clauses methods. like as where, orWhere, whereBetween, whereNotBetween, whereIn, whereNotIn, whereNull, whereNotNull, whereDate, whereMonth, whereDay, whereYear, whereTime and whereColumn.
Normally we want to need when filter data into the table. At that time we use the Where Clauses Methods. so let’s see below an example of Where Clauses Methods.
Where Clause
$users = DB::table('users')->where('votes', '=', 100)->get();
orWhere Clause
$users = DB::table('users') ->where('votes', '>', 100) ->orWhere('name', 'John') ->get();
whereBetween Clause
$users = DB::table('users') ->whereBetween('votes', [1, 100])->get();
whereNotBetween Clause
$users = DB::table('users') ->whereNotBetween('votes', [1, 100]) ->get();
whereIn Clause
$users = DB::table('users') ->whereIn('id', [1, 2, 3]) ->get();
whereNotIn Clause
$users = DB::table('users') ->whereNotIn('id', [1, 2, 3]) ->get();
whereNull Clause
$users = DB::table('users') ->whereNull('updated_at') ->get();
whereNotNull Clause
$users = DB::table('users') ->whereNotNull('updated_at') ->get();
whereDate Clause
$users = DB::table('users') ->whereDate('created_at', '2016-12-31') ->get();
whereMonth Clause
$users = DB::table('users') ->whereMonth('created_at', '12') ->get();
whereDay Clause
$users = DB::table('users') ->whereDay('created_at', '31') ->get();
whereYear Clause
$users = DB::table('users') ->whereYear('created_at', '2016') ->get();
whereTime Clause
$users = DB::table('users') ->whereTime('created_at', '=', '11:20:45') ->get();
whereColumn Clause
$users = DB::table('users') ->whereColumn('first_name', 'last_name') ->get();