Esempio n. 1
0
 /**
  * @param $model
  */
 public function handle($model)
 {
     if (uses_trait($model, Translatable::class)) {
         $related = $model->translations()->getRelated();
         if ($related instanceof OwnsSlug) {
             $model->load(['translations', 'translations.slug']);
         }
     }
 }
Esempio n. 2
0
 /**
  * @param $object
  */
 public function handle($object)
 {
     //we need to check for owns slug on the model itself,
     //or on translation model.
     //our db takes care of foreign key deletion.
     //so there is no 'eloquent.deleted' for our translation
     //if we deleted the parent.
     if ($object instanceof OwnsSlug) {
         $object->slug()->delete();
     }
     if (uses_trait($object, Translatable::class)) {
         $related = $object->translations()->getRelated();
         if ($related instanceof OwnsSlug) {
             foreach ($object->translations as $translation) {
                 $translation->slug()->delete();
             }
         }
     }
 }
Esempio n. 3
0
 /**
  * keep this public, this allows for easy searching inheriting.
  *
  * @param Searchable $inheritFrom
  * @return array
  */
 public function getSearchableSuggestData(Searchable $inheritFrom = null)
 {
     $data = [];
     if (uses_trait($this, Translatable::class)) {
         //foreach locale we add a different suggest
         foreach (Locale::all() as $locale) {
             $translation = $this->translate($locale->slug);
             if (!$translation) {
                 continue;
             }
             $data[$this->getSearchableSuggestName($locale, $inheritFrom)] = $this->getSearchableSuggestPayload($translation);
         }
     }
     return $data;
 }
Esempio n. 4
0
 /**
  * @param null $type
  * @param null $size
  * @return string
  * @throws Exception
  */
 public function getMediaFolder($type = null, $size = null)
 {
     if (uses_trait($this, ModelAccountResource::class)) {
         $account = isset($this->attributes['account_id']) ? $this->attributes['account_id'] : app('Modules\\Account\\AccountManager')->account()->id;
         $media = str_replace('{account}', $account, $this->media);
     } else {
         $media = $this->media;
     }
     /** @var Configurator $config */
     $config = app('Modules\\Media\\Configurator');
     if (empty($type)) {
         return sprintf('%s/%d/', $media, $this->attributes['id']);
     }
     if (!empty($type) && !$config->isSupportedMediaType($type)) {
         throw new InvalidArgumentException('Need valid media type to return a proper folder');
     }
     if (!property_exists(get_class($this), 'media')) {
         throw new Exception('Please define media attribute on your model');
     }
     if (!$size) {
         return sprintf('%s/%d/%s/', $media, $this->attributes['id'], $type);
     }
     return sprintf('%s/%d/%s/%s/', $media, $this->attributes['id'], $type, $size);
 }
Esempio n. 5
0
 /**
  * @param Searchable $type
  */
 public function delete(Searchable $type)
 {
     if (uses_trait($type, MySoftDeletes::class)) {
         //only delete when fully being deleted.
         if ($type->beingFullyDeleted()) {
             $params = $this->data($type);
             $params = array_except($params, ['body']);
             $this->client->delete($params);
         }
         //maybe we should trigger an update here instead of doing nothing.
     } else {
         //Even regular soft deletes can be deleted.
         $params = $this->data($type);
         $params = array_except($params, ['body']);
         $this->client->delete($params);
     }
 }
Esempio n. 6
0
 /**
  * @param $type
  * @return bool
  */
 protected function usesTranslations($type)
 {
     $class = $this->getClass($type);
     return uses_trait(new $class(), Translatable::class);
 }