This package allows you to store entries for specific collections to the database via Laravel's Eloquent ORM.
Structures are disabled for performance reasons.
- PHP 8+
- Statamic v4
Eloquenty uses Statamic Eloquent Driver (https://github.com/statamic/eloquent-driver) but with modifications that allows to use the driver for specific collections entries instead for every entry.
Both standard and Eloquenty collections will be visible under /cp/collections
but the Entries column will display the message
"Managed by Eloquenty" for Eloquenty collections.
Eloquenty collections are managed on a separate route /cp/eloquenty/collections
which is a clone of /cp/collections
route group
with modifications to use the Entry and EntryRepository classes under Eloquenty\Entries that uses Eloquent ORM. The Entry related
classes and Controllers are extending the original Statamic classes.
There's a middleware that redirects from /cp/collections/{collection}
to /cp/eloquenty/collections/{collection}
when clicking to
view Eloquenty collections under /cp/collections
.
Collection modifications should be performed under the original /cp/collections
route.
You can install this package via composer using:
composer require nfragkos/eloquenty
The package will automatically register itself.
-
Publish eloquenty config and migration files:
php artisan vendor:publish --provider="Eloquenty\ServiceProvider"
-
Run
php artisan migrate
to create Eloquenty table.
(Make sure laravel is configured properly and schema is created. See https://laravel.com/docs/8.x/database#configuration) -
Create a new collection or enter existing collection handle in config/eloquenty.php:
'collections' => [ 'blog', ],
This means that the entries for blog collection will be handled by Eloquenty.
-
If you entered an existing collection to Eloquenty config, there's an import command to import entries to the database:
php artisan eloquenty:import-entries blog
Please delete your collection entries from the filesystem after you verify that entries are imported successfully.
Eloquenty now should be visible now under Content section of the navigation menu in Control Panel. CRUD for Eloquenty collections works the same way as standard collections.
In Antlers templates use the eloquenty
tag instead of the collection tag for Eloquenty collections:
{{ eloquenty from="blog" limit="10" taxonomy:tags="demo|example" sort="date:desc" }}
<a href="{{ url }}">{{ title }}</a>
{{ /eloquenty }}
Calling the queryEntries() method of Collection repository, will return the correct QueryBuilder for Eloquenty collections:
\Statamic\Facades\Collection::find('blog')->queryEntries()
Alternatively you can use the Facade Eloquenty::repository() method or EloquentyEntry::query() to retrieve the instance of EntryRepository
(implements Statamic\Contracts\Entries\EntryRepository
):
Eloquenty\Facades\Eloquenty::repository()
Eloquenty\Facades\EloquentyEntry::query()
Keep in mind that calling the whereCollection() method will fetch all entries in the table. You should use the query() method instead that returns the query builder instance to build your query.
Please see CHANGELOG for more information what has changed recently.
Pull requests are welcome and will be fully credited.
- Fork the repo and create your branch from
main
branch. - Update the README file if needed.
- Make sure your code follows the PSR-2 coding standard.
- Issue that pull request!
The MIT License (MIT). Please see License File for more information.
Many thanks to Statamic for the Eloquent driver and the awesome CMS ❤️
If you like this addon please consider buying me a coffee: