Is it possible to use Eloquent without Laravel or does somebody knows a equally easy to use ORM?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With