Laravel 7 Where Clauses Methods Example Tutorial
In this article, We will explain to you how to use where clauses Method in laravel 7. 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
1 | $users = DB::table('users')->where('votes', '=', 100)->get(); |
orWhere Clause
1 2 3 4 | $users = DB::table('users') ->where('votes', '>', 100) ->orWhere('name', 'John') ->get(); |
whereBetween Clause
1 2 | $users = DB::table('users') ->whereBetween('votes', [1, 100])->get(); |
whereNotBetween Clause
1 2 3 | $users = DB::table('users') ->whereNotBetween('votes', [1, 100]) ->get(); |
whereIn Clause
1 2 3 | $users = DB::table('users') ->whereIn('id', [1, 2, 3]) ->get(); |
whereNotIn Clause
1 2 3 | $users = DB::table('users') ->whereNotIn('id', [1, 2, 3]) ->get(); |
whereNull Clause
1 2 3 | $users = DB::table('users') ->whereNull('updated_at') ->get(); |
whereNotNull Clause
1 2 3 | $users = DB::table('users') ->whereNotNull('updated_at') ->get(); |
whereDate Clause
1 2 3 | $users = DB::table('users') ->whereDate('created_at', '2016-12-31') ->get(); |
whereMonth Clause
1 2 3 | $users = DB::table('users') ->whereMonth('created_at', '12') ->get(); |
whereDay Clause
1 2 3 | $users = DB::table('users') ->whereDay('created_at', '31') ->get(); |
whereYear Clause
1 2 3 | $users = DB::table('users') ->whereYear('created_at', '2016') ->get(); |
whereTime Clause
1 2 3 | $users = DB::table('users') ->whereTime('created_at', '=', '11:20:45') ->get(); |
whereColumn Clause
1 2 3 | $users = DB::table('users') ->whereColumn('first_name', 'last_name') ->get(); |
Please follow and like us: