10.2 Where Clauses
So now we have the methods that we need to retrieve our database results, how can we apply
conditions to these SQL queries? Well in the example above you saw me using the where()
method, let’s take a closer look at this.
1 <?php
2
3 $users = DB::table('users')->where('username', '=', 'dayle')->get();
Here we have the same snippet again, but we are concentrating on the where() part of the chain
:
1 <?php
2
3 where('username', '=', 'dayle')
The great thing about how Laravel handles the where clause is that the chain looks a little bit like
the SQL being generated. In the chain method above we are saying WHERE username = 'dayle'.
The first parameter to the method states the field which we are comparing, the second parameter
states the operator to use for the comparison, and the third parameter is the value which we are
comparing with. We could also use :
Anil Bist
Skills Laravel
Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-
I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore