kodeine / laravel-meta

Fluent Meta Data for Eloquent Models, as if it is a property on your model
MIT License
400 stars 90 forks source link

Update MetaData.php #80

Closed ricardomartos closed 2 years ago

ricardomartos commented 3 years ago

change connection name if env 'METADATA_DATABASE' is set

kodeine commented 3 years ago

Please update the readme as well to reflect the addition of env variable

ricardomartos commented 3 years ago

@kodeine I think is ready now ;)

ricardomartos commented 3 years ago

If you are using this package with a secondary database connection, you can set the METADATA_DATABASE variable in your .env in order to let this package know the secondary connection database name.

CONNECTION 1

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=<NAME>
DB_USERNAME=<USERNAME>
DB_PASSWORD=<PASSWORD>

CONNECTION 2

DB_CONNECTION=mysql
DB_HOST=<SOME_OTHER_HOST>
DB_PORT=3306
DB_DATABASE=<NAME> <--
DB_USERNAME=<USERNAME>
DB_PASSWORD=<PASSWORD>
// TWO OPTIONS
METADATA_DATABASE=<NAME>
// OR
METADATA_DATABASE='${DB_DATABASE}'
siamak2 commented 2 years ago

This PR has two major problems:

  1. you really shouldn't use env outside of config directory as explained in Laravel's documention
  2. Laravel relations won't work between two connections