-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
113 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
### Connection | ||
Library uses Laravel Capsule for connections. | ||
For Laravel apps, it's trying to use default connection and can be used as is. | ||
For other cases, initialize a Capsule instance: | ||
```php | ||
$capsule = new Capsule; | ||
$capsule->addConnection([ | ||
// connection settings | ||
]); | ||
$this->capsule = $capsule; | ||
$capsule->setAsGlobal(); | ||
$capsule->bootEloquent(); | ||
``` | ||
|
||
### Work with migrations, cli-application | ||
CLI app relies on a database connection. It uses [Doctrine DBAL](https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#configuration) to perform connections.<br /> | ||
There isn't any pre-configured connection information. For non-docker environments is required to set up a connection. | ||
As an option, make a new file connection.php in root folder. This file will be automatically included. | ||
```php | ||
#connection.php | ||
use Drobotik\Eav\Database\Connection; | ||
$config = [ | ||
// connection settings | ||
] | ||
$connection = Connection::get($config) | ||
``` | ||
Note use a [driver](https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#driver) that suits your needs. | ||
|
||
Migrate: | ||
```bash | ||
$ php eav migrations:migrate latest | ||
``` | ||
|
||
### Laravel migrations support | ||
It also contains laravel migrations for publishing on Laravel app. Add EavServiceProvider to | ||
providers config array. | ||
```php | ||
\Drobotik\Eav\Database\Support\Laravel\EavServiceProvider::class | ||
``` | ||
Publish migrations by vendor:publish. | ||
|
||
## Example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## Documentation | ||
|
||
- [database](./database.md) | ||
- [entity](./examples.md) | ||
- [attribute](./examples.md) | ||
- [attribute set](./examples.md) | ||
- [attribute group](./examples.md) | ||
- [value](./examples.md) | ||
- [import](./examples.md) | ||
- [export](./examples.md) | ||
- [examples](./examples.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
```php | ||
// make data | ||
$domain = $this->eavFactory->createDomain(); | ||
$attrSet = $this->eavFactory->createAttributeSet($domain); | ||
$group = $this->eavFactory->createGroup($attrSet); | ||
$stringAttribute = $this->eavFactory->createAttribute($domain, [ | ||
_ATTR::NAME->column() => "name", | ||
_ATTR::TYPE->column() => ATTR_TYPE::STRING->value() | ||
]); | ||
$integerAttribute = $this->eavFactory->createAttribute($domain, [ | ||
_ATTR::NAME->column() => "age", | ||
_ATTR::TYPE->column() => ATTR_TYPE::INTEGER->value() | ||
]); | ||
$this->eavFactory->createPivot($domain, $attrSet, $group, $stringAttribute); | ||
$this->eavFactory->createPivot($domain, $attrSet, $group, $integerAttribute); | ||
$data = [ | ||
"name" => $this->faker->name, | ||
"age" => $this->faker->randomNumber(), | ||
]; | ||
// create new | ||
$entity = new Entity(); | ||
$entity->setDomainKey($domain->getKey()); | ||
$entity->getAttributeSet()->setKey($attrSet->getKey()); | ||
$entity->getBag()->setFields($data); | ||
$result = $entity->save(); | ||
$id = $entity->getKey() | ||
// find | ||
$entity = new Entity(); | ||
$entity->find($id); | ||
$data = $entity->toArray(); | ||
// update | ||
$entity->getBag()->setField("name", "new name") | ||
$result = $entity->save(); | ||
// delete | ||
$entity->delete(); | ||
``` |