Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Eloquent ORM without Laravel?

Is it possible to use Eloquent without Laravel or does somebody knows a equally easy to use ORM?

like image 451
Andre Zimpel Avatar asked May 19 '13 10:05

Andre Zimpel


People also ask

Can I use eloquent ORM without Laravel?

If you want, you can use Eloquent without Laravel. Actually, Laravel is not a monolithic framework. It is made up of several, separate parts, which are combined together to build something greater.

How does eloquent ORM work?

Eloquent is an object relational mapper (ORM) that is included by default within the Laravel framework. An ORM is software that facilitates handling database records by representing data as objects, working as a layer of abstraction on top of the database engine used to store an application's data.

What is the difference between query builder and eloquent ORM?

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.


2 Answers

Yes you can. A while ago Dan Horrigan released a package called Capsule for Laravel 4 which allowed Eloquent to be used independently and with minimal setup. The package itself has been merged with the L4 core so you no longer need to use the package.

If you refer to the illuminate/database repository there is a nice little introduction on using Eloquent without the framework.

Here is a small excerpt of getting it up and running.

$capsule = new Illuminate\Database\Capsule($config);

$capsule->bootEloquent();

$capsule->connection()->table('users')->where('id', 1)->first();

Update

Dan Horrigan has since removed his Capsule implementation as it is now built directly into Eloquent. Refer to the above illuminate/database link for more details on how to use Capsule.

like image 68
Jason Lewis Avatar answered Oct 06 '22 20:10

Jason Lewis


Check out https://github.com/Luracast/Laravel-Database it provides full eloquent support including artisan migrations and more for the latest Laravel 8.* components.

It uses capsule and lazy loads the components when they are used.

Disclosure: I'm the author of this repository

like image 1
Arul Kumaran Avatar answered Oct 06 '22 18:10

Arul Kumaran