mmx / database
Eloquent for MODX 3
Requires
- php: >=7.4
- illuminate/database: ^v8.83|^v10.47
- illuminate/events: ^v8.83|^v10.47
Requires (Dev)
- modx/revolution: ^v3.0
- phpunit/phpunit: ^9.6
README
This extra is part of MMX initiative - the Modern MODX approach.
Prepare
This package can be installed only with Composer.
If you are still not using Composer with MODX 3, just download the composer.json
of your version:
cd /to/modx/root/
wget https://raw.githubusercontent.com/modxcms/revolution/v3.0.4-pl/composer.json
Then run composer update --no-dev
and you are ready to install the mmx packages.
Install
composer require mmx/database --update-no-dev
composer exec mmx-database install
Remove
composer exec mmx-database remove
composer remove mmx/database
How to use
mmxDatabase
service will be registered globally, so you can use its models anywhere in your PHP code inside MODX.
Get all published resources with Template and TV values.
$resources = \MMX\Database\Models\Resource::query() ->with('Template:id,templatename') ->with('TvValues') ->where('published', true) ->get(); foreach ($resources as $resource) { print_r($resource->toArray()); }
Get categories with relations:
$categories = \MMX\Database\Models\Category::query() ->with('Templates') ->with('Plugins') ->with('Snippets') ->with('Chunks') ->with('Tvs') ->get(); foreach ($categories as $category) { print_r($category->toArray()); }
You can see all currently available models with their relations in Models directory.
Do not forget to read the official Eloquent documentation.
Nota bene!
mmxDatabase models are not contain any MODX related logic, like clearing cache or calling plugin events.
This is just a convenient way to work with MODX database directly, without xPDO.
Project is still under development, do not hesitate to use issues if you have any.