Download the PHP package leinonen/yii2-eloquent without Composer
On this page you can find all versions of the php package leinonen/yii2-eloquent. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download leinonen/yii2-eloquent
More information about leinonen/yii2-eloquent
Files in leinonen/yii2-eloquent
Package yii2-eloquent
Short Description Drop in implementation of the Illuminate Database component for Yii2
License MIT
Informations about the package yii2-eloquent
Yii2-eloquent
A drop in Laravels Eloquent and Illuminate/Database implementation for Yii2
Features:
- [x] Working extension (Still need to check Eloquent events and pagination)
- [x] Migrations
- [x] Fixtures
- [x] Yii style model validation for Eloquent models
- [x] Ability to feed Eloquent models to ActiveForm widget
- [ ] Model factories for use with testing instead of Fixtures?
- [ ] Other Laravel test helpers for Eloquent models?
- [ ] Adapter for Yii::$app->db? It's confusing to use it now in IDE with autocompletion and creating an own Yii base class is too much work
- [ ] Better Docs
Installation
Require this package, with Composer, in the root directory of your project.
Configuration:
To configure the package just override and bootstrap your Yii db component in the application config.
Usage:
Like said, by default the package overrides Yii's database component. So one you can access Illuminate\Database\Capsule\Manager
like this:
However its much more preferable to access the capsule with static methods or inject it via dependency injection. IDEs cannot autocomplete accessing the db component from the Yii god object.
For complete docs please refer to: Illuminate\Database and Laravel
Eloquent
Using Eloquent is covered in Laravels documentation. However this package provides also an altenrative base model which to extend form. By extending from leinonen\Yii2Eloquent\Eloquent\Model
instead of Illuminate\Database\Eloquent\Model
you'll get some Yii functionalities to your Eloquent models. For example you can then declare rules()
scenarios()
etc. as you are used with Yiis AR models. These can then be also fed to ActiveForm widget, validated using $model->validate()
etc.
Simple example of Eloquent Model:
The package also provides a simple trait to make your Eloquent user model compatible with Yii's IdentityInterface. Just use leinonen\Yii2Eloquent\Eloquent\AuthenticatableTrait;
Migrations
If you want to use Yiis basic migration commands you have overwrite the default migration controller in the console app config.
Then all the commands php yii migrate/create
etc. will work as expected. Note that you have to use the Capsule
in migrations instead of refering to Yiis base migration class:
Fixtures
If you like Yiis fixtures no worries! Just extend leinonen\Yii2Eloquent\Fixtures\EloquentFixture
when creating the Fixture class and everything will work as usual:
All versions of yii2-eloquent with dependencies
illuminate/events Version ^5.1
illuminate/pagination Version ^5.1
yiisoft/yii2 Version ^2.0