コード例 #1
0
 /**
  * @param Request $request
  * @param Locale $locale
  * @return mixed
  */
 public function store(Request $request, Locale $locale)
 {
     $owner = $this->owner($request);
     $file = $request->file('file');
     $infographic = $this->dispatch(new UploadNewInfographic($owner, $file, $locale->whereSlug($request->get('locale'))->firstOrFail()));
     $infographic->load('sizes');
     return $infographic;
 }
コード例 #2
0
 /**
  * @param Request $request
  * @param Locale $locale
  * @return array|JsonResponse|mixed|null|\Symfony\Component\HttpFoundation\File\UploadedFile
  */
 public function store(Request $request, Locale $locale)
 {
     $owner = $this->owner($request);
     $file = $request->file('file');
     $file = $this->dispatch(new UploadNewFile($owner, $file, $locale->whereSlug($request->get('locale'))->firstOrFail()));
     if (!$file) {
         return new JsonResponse('Something went wrong, check for duplicate filename', 400);
     }
     return $file;
 }
コード例 #3
0
ファイル: SiteSluggable.php プロジェクト: jaffle-be/framework
 /**
  * Set the slug manually.
  *
  * $slug
  * @param $uri
  */
 protected function setSlug($uri)
 {
     if (empty($uri)) {
         return;
     }
     //for site sluggables, we do not need to configure anything as we know how we'll name our slug
     //and what relation it uses.
     //all we need to check is.. does it exist? if not, create a new one.
     //if so, update it.
     //old way of handling locales with simple string values
     if (isset($this->attributes['locale'])) {
         $locale = Locale::whereSlug($this->attributes['locale'])->first();
     } else {
         $locale = $this->locale;
     }
     //to find the account id, we'd need the parent document, not the translation document
     //since we didn't define our translation to use a general name, we need to use an interface function
     //which returns a value for us. (and which we can define on each model)
     //both this part and the part for the locales should be cleaned up once we upgrade our system
     //to only use the locale class and not the locale string values.
     //do not change it into :
     //
     //# $account = app('Modules\Account\AccountManager')->account();
     //
     //that would be wrong when we're doing some sort of console command
     //without an actual account reference within accountmanager
     $account = $this->getAccount();
     $this->load('slug');
     if (!($slug = $this->slug)) {
         //slugs should always be account specific, at least for now
         $slug = new Uri(['account_id' => $account->id, 'locale_id' => $locale->id, 'uri' => $uri]);
         $this->slug()->save($slug);
     } else {
         //consider a post as our example resource from now on
         //whenever we update a post its title... we'll be working in a draft.
         //this means that we do not need to save a new uri instance.
         //an uri only becomes active and should then be inserted, when an actual draft is published.
         //the same goes for editing an existing post.
         //when editing a post, you'll actually edit a revision. which will not be online until you publish it.
         //when you publish it, the old post will be taken 'offline'
         //the new post will be created, which will trigger the new uri insertion.
         //the canonical is probably something that needs to be implemented together with the allowRevisions trait
         //instead of implementing it in the uri table
         //when updating the slug, we need to insert a new uri, and set the canonical
         $this->slug->uri = $uri;
         $this->slug->save();
     }
 }
コード例 #4
0
ファイル: SeoTrait.php プロジェクト: jaffle-be/framework
 /**
  * @param $field
  * @return bool
  */
 protected function getSeoCustomisation($field)
 {
     static $locale;
     if (!$locale) {
         $locale = app()->getLocale();
         $locale = Locale::whereSlug($locale)->first();
     }
     if ($this->seo) {
         $localised = $this->seo->first(function ($key, $item) use($locale) {
             return $item->locale_id == $locale->id;
         });
         if ($localised) {
             return $localised->{$field};
         }
     }
     return false;
 }