/**
  * Stores a new project.
  * POST /api/v1/projects
  *
  * @param  Request $request Request that has been made.
  *
  * @return array
  */
 public function store(Request $request)
 {
     $this->validate($request, $this->rules);
     $data = $request->only(['project_id', 'name', 'group', 'url']);
     $project = $this->model->firstOrCreate($data);
     return ['status' => 'success', 'message' => 'Successfully created project.', 'resource' => $this->createJsonApiOutput($project)];
 }
 /**
  * Creates a translation.
  *
  * @param Model  $locale
  * @param string $text
  * @param Model  $parentTranslation
  *
  * @return Model
  */
 protected function firstOrCreateTranslation(Model $locale, $text, $parentTranslation = null)
 {
     // We'll check to see if there's a cached translation
     // first before we try and hit the database.
     $cachedTranslation = $this->getCacheTranslation($locale, $text);
     if ($cachedTranslation instanceof Model) {
         return $cachedTranslation;
     }
     // Check if auto translation is enabled. If so we'll run
     // the text through google translate and
     // save it, then cache it.
     if ($parentTranslation && $this->autoTranslateEnabled()) {
         $googleTranslate = new TranslateClient();
         $googleTranslate->setSource($parentTranslation->locale->code);
         $googleTranslate->setTarget($locale->code);
         try {
             $text = $googleTranslate->translate($text);
         } catch (ErrorException $e) {
             // Request to translate failed, set the text
             // to the parent translation
             $text = $parentTranslation->translation;
         } catch (UnexpectedValueException $e) {
             // Looks like something other than text was passed in,
             // we'll set the text to the parent translation
             // for this exception as well
             $text = $parentTranslation->translation;
         }
     }
     $translation = $this->translationModel->firstOrCreate([$locale->getForeignKey() => $locale->getKey(), $this->translationModel->getForeignKey() => isset($parentTranslation) ? $parentTranslation->getKey() : null, 'translation' => $text]);
     // Cache the translation so it's retrieved faster next time
     $this->setCacheTranslation($translation);
     return $translation;
 }
Example #3
0
 /**
  * Retrieves or creates a locale from the specified code.
  *
  * @param string $code
  *
  * @return Model
  */
 protected function firstOrCreateLocale($code)
 {
     $cachedLocale = $this->getCacheLocale($code);
     if ($cachedLocale) {
         return $cachedLocale;
     }
     $name = $this->getConfigLocaleByCode($code);
     $locale = $this->localeModel->firstOrCreate(['code' => $code, 'name' => $name]);
     $this->setCacheLocale($locale);
     return $locale;
 }
Example #4
0
 public static function firstOrCreate(array $attributes)
 {
     $user = parent::firstOrCreate($attributes);
     // should update the database with some info when creating
     // if( !$user->name ) {
     // always updates the name,
     try {
         $response = FacebookUtil::getInstance()->graphRequest('GET', $attributes['facebook_id']);
         if ($response->getStatusCode() == 200) {
             $user->name = json_decode($response->getBody()->getContents())->name;
             $user->save();
         }
     } catch (RequestException $e) {
         return response()->json(['message' => trans('auth.facebook_request_failed')], 500);
     }
     // }
     return $user;
 }
Example #5
0
 public function firstOrCreate(array $data)
 {
     return $this->model->firstOrCreate($data);
 }