Example #1
0
 public function get($limit = 30)
 {
     $query = MavenUniqueKey::with('faqs.tags')->orderBy('sort', 'asc');
     if (!$this->_draft_flag) {
         $query->where('draft_flag', false);
     }
     if (count($this->_tags) > 0) {
         $tag_query = MavenTag::join('maven_faqs', 'maven_tags.faq_id', '=', 'maven_faqs.id');
         foreach ($this->_tags as $locale => $tags) {
             foreach ($tags as $tag) {
                 $tag_query->orWhere(function ($query) use($locale, $tag) {
                     $query->where('maven_faqs.locale', $locale)->where('maven_tags.tag', $tag);
                 });
             }
         }
         $unique_key_ids = $tag_query->lists('maven_tags.unique_key_id');
         $query->whereIn('id', $unique_key_ids);
     }
     if (count($this->_unique_keys) > 0) {
         $query->where(function ($query) {
             foreach ($this->_unique_keys as $unique_key) {
                 $query->orWhere('unique_key', $unique_key);
             }
         });
     }
     return $query->paginate($limit);
 }
Example #2
0
 private function saveSubData($unique_key_id, $request)
 {
     foreach (config('maven.locales') as $locale => $name) {
         $faq = MavenFaq::FirstOrNew(['unique_key_id' => $unique_key_id, 'locale' => $locale]);
         $faq->unique_key_id = $unique_key_id;
         $faq->question = $request->questions[$locale];
         $faq->answer = $request->answers[$locale];
         $faq->locale = $locale;
         $faq->save();
         MavenTag::where('faq_id', $faq->id)->delete();
         if (!empty($request->tags[$locale])) {
             $locale_tags = explode(',', $request->tags[$locale]);
             foreach ($locale_tags as $locale_tag) {
                 $tag = new MavenTag();
                 $tag->unique_key_id = $unique_key_id;
                 $tag->faq_id = $faq->id;
                 $tag->tag = $locale_tag;
                 $tag->save();
             }
         }
     }
 }
Example #3
0
 public function scopeFilterTag($query, $value)
 {
     $unique_key_id = MavenTag::where('tag', 'LIKE', '%' . $value . '%')->lists('unique_key_id');
     return $query->whereIn('id', $unique_key_id);
 }