Member-only story

Difference between find and where clause in Laravel.

Joy Joel
4 min readSep 30, 2021

--

Laravel’s database query builder provides a convenient, fluent interface to creating and running database queries. It can be used to perform most database operations in your application and works on all supported database systems.

There are several database query builder, like;

  • Aggregates
  • Chunking
  • Selects
  • Joins
  • Unions
  • Raw Expressions
  • Where
  • Ordering, Grouping, etc.

Where Clause

The where method is used on a query builder instance to add where clauses to the query. Let’s now look at how to retrieve a record using the where clause:

$c->where(‘id’,’=’,1)->get();

$c->where(‘id’,’=’,1)->get() calls the where method on our instance variable. We pass in the first argument id which is the database field where we want to apply the filter. = is the comparison operator for our condition. 1 is the filter value for our condition. We then call the get method which reprieves the record.

The SQL statement equivalent of this query is SELECT * FROM categories WHERE id = 1.

Note: I am using an existing laravel project and php tinker on my terminal to practice. On your terminal, type php artisan tinker

--

--

Joy Joel
Joy Joel

Written by Joy Joel

Abba’s Daughter| DevOps Engineer|Technical Writer

No responses yet

Write a response