Skip to content

Allow own Model by configuration #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Allow own Model by configuration #268

wants to merge 11 commits into from

Conversation

Nowi5
Copy link
Contributor

@Nowi5 Nowi5 commented Jun 17, 2018

Similar to Spatie/Analytics I would like to allow to set the Model by the config file. This provides the opportunity that the developer can extend the given model and enhance it. I have done this to improve performance by Model cache.

My config file:

    /*
     * This model will be used to maintain translations. The only requirement is that
     * it should be or extend the Barryvdh\TranslationManager\Models\Translation model.
     */
    'translation_model' => Barryvdh\TranslationManager\Models\Translation::class,

My Model:

<?php 
namespace  App\Models\Barryvdh;

use Illuminate\Database\Eloquent\Model;
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
use Barryvdh\TranslationManager\Models\Translation as TranslationModel;

class Translation extends TranslationModel{

    use Cachable;

}

With that we can close #227

Simon added 10 commits March 11, 2018 22:38
…d adjust configuration. Code similar to Spatie\Activitylog
…ion-manager into barryvdh-master

# Conflicts:
#	config/translation-manager.php
#	src/Manager.php
…ion-manager

# Conflicts:
#	config/translation-manager.php
#	src/Manager.php
…Spatie\Activitylog. Update after merge. An example which is increasing performance a lot:

Config:
'translation_model' => App\Models\Barryvdh\Translation::class,

Own Translation Model:
<?php
namespace  App\Models\Barryvdh;

use Illuminate\Database\Eloquent\Model;
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
use Barryvdh\TranslationManager\Models\Translation as TranslationModel;

class Translation extends TranslationModel{

    use Cachable;

}
@isecchin
Copy link

I'm also using another package (hyn/multi-tenant) for a multi-tenant application, and have the tenant's connection set as the default, but the translation table is stored on the system's DB.

For that, the package provides a trait to use on the models to force a specific connection (system or tenant), but since the Translation Model cannot be overwritten, I can't apply the trait without forking the project.

I think this would be a very nice addition to the package !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple database calls for the same key
2 participants