Issues (238)

src/Traits/TranslatableObserver.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Translation\Traits;
4
5
use Translation\Models\Translation;
6
use Translation\Repositories\TranslationRepository;
7
8
/**
9
 * For Model
10
 */
11
class TranslatableObserver
12
{
13
    /**
14
     *  Save translations when model is saved.
15
     *
16
     * @param  Model $model
0 ignored issues
show
The type Translation\Traits\Model was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
     * @return void
18
     */
19
    public function saved($model)
20
    {
21
        $translationRepository = \App::make(TranslationRepository::class);
22
        $cacheRepository       = \App::make('translation.cache.repository');
23
        foreach ($model->translatableAttributes() as $attribute) {
24
            // If the value of the translatable attribute has changed:
25
            if ($model->isDirty($attribute)) {
26
                $translationRepository->updateDefaultByCode($model->translationCodeFor($attribute), $model->getRawAttribute($attribute));
27
            }
28
        }
29
        $cacheRepository->flush(\Illuminate\Support\Facades\Config::get('app.locale'), 'translatable', '*');
30
    }
31
32
    /**
33
     *  Delete translations when model is deleted.
34
     *
35
     * @param  Model $model
36
     * @return void
37
     */
38
    public function deleted($model)
39
    {
40
        $translationRepository = \App::make(TranslationRepository::class);
41
        foreach ($model->translatableAttributes() as $attribute) {
42
            $translationRepository->deleteByCode($model->translationCodeFor($attribute));
43
        }
44
    }
45
}
46