Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are differences between Eloquent and Query Builder in laravel 5.1?

When I start query data from database I don't know what way I should use Eloquent or Query Builder. what is the best choice? Eloquent is write less than Query builder but I cannot control input field while Query builder write more but I can manual input field by myself. What something else do I have to know more about them?

like image 441
SRENG Khorn Avatar asked Sep 08 '15 07:09

SRENG Khorn


People also ask

What is difference between eloquent and query builder in Laravel?

Eloquent ORM is best suited working with fewer data in a particular table. On the other side, query builder takes less time to handle numerous data whether in one or more tables faster than Eloquent ORM. In my case, I use ELoquent ORM in an application with tables that will hold less than 17500 entries.

What is eloquent builder in Laravel?

The Eloquent ORM included with Laravel provides a beautiful, simple ActiveRecord implementation for working with your database. Each database table has a corresponding "Model" which is used to interact with that table. Models allow you to query for data in your tables, as well as insert new records into the table.

What is the difference between query builder and ORM?

If you dealing with one entity go for ORM, (Eloquent). If you dealing with multiple entities it's better to deal with query builder. If you are new to mysql or your application is not very complex, definitely choose ORM. If you need more complex query, I recommend to use query builder.

What is the query builder in Laravel?

Introduction. 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 perfectly with all of Laravel's supported database systems.


1 Answers

There is not best choice. The choice depends entirely in your needs. Using Eloquent has the advantages of using an ORM, and its disadvantages.

In general, the main advantage of Eloquent against query builder is the speed of development. And that reduces development cost.

The main disadvantage is that the ORMs tend to be slower, and that the developer is less in control of the database management.

For most projects, where no very complex queries are needed, the best is start using ORM. Afterwards, if you are in the need of optimise the app, you can translate them to queries that will perform better.

like image 114
Postizo Avatar answered Nov 14 '22 22:11

Postizo