/**
  * Register any application services.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('eloquent.saving*', function ($model) {
         if ($model instanceof Article) {
             $articles = Article::select('slug')->get();
             $slug = str_slug($model->title);
             $i = 0;
             do {
                 $flag = false;
                 foreach ($articles as $article) {
                     if ($article->slug == $slug) {
                         $flag = true;
                         $slug .= "-" . $i;
                         ++$i;
                     }
                 }
             } while ($flag);
             $model->slug = $slug;
         } else {
             if ($model instanceof Member) {
             } else {
                 if ($model instanceof Command) {
                 }
             }
         }
     });
 }
 /**
  * Display the home page.
  *
  * @param Request $requests
  *
  */
 public function scopeSearch(Request $requests)
 {
     $keyword = $requests->get('q');
     $results = null;
     if (isset($keyword) && trim($keyword) != "") {
         $results = Article::select('id', 'title', 'intro', 'page_image')->where('title', 'LIKE', '%' . $keyword . '%')->where('is_checked', true)->published()->paginate(10);
     }
     return view('front.search')->with('articles', $results);
 }
Example #3
0
 /**
  * Exporta el Listado de todos los articulos en formato Excel
  */
 public function excelArticles()
 {
     Excel::create('Maestro de Artículos', function ($excel) {
         $excel->sheet('Articulos', function ($sheet) {
             $articles = Article::select('product_code', 'name', 'active', 'barcode')->orderBy('name')->get();
             $sheet->fromArray($articles);
         });
     })->export('xlsx');
 }
Example #4
0
 /**
  * get tags ajax
  */
 public function getAjaxTags(Request $request)
 {
     $tags = Article::select('meta_key')->where('meta_key', 'LIKE', '%' . $request->input('text') . '%')->take(20)->get();
     $results = array();
     $output = '<ul>';
     if (count($tags) > 0) {
         foreach ($tags as $tag) {
             $t = explode(', ', $tag->meta_key);
             $result = preg_grep('~' . $request->input('text') . '~', $t);
             $result = reset($result);
             if (!empty($result)) {
                 $results[] = $result;
             }
         }
         if (count($results) > 0) {
             foreach (array_unique($results) as $res) {
                 $output .= '<li data-name="' . $res . '">' . $res . '</li>';
             }
         }
     } else {
         return 0;
     }
     $output .= '</ul>';
     return $output;
 }
Example #5
0
 /**
  * article datas.
  *
  * @return \Illuminate\Http\Response
  */
 public function datas()
 {
     return Datatables::of(Article::select('*'))->make(true);
 }
Example #6
0
 public function showSerialsList(Article $article, $slug)
 {
     $catName = Cat::select('name')->where('slug', $slug)->take(1)->get();
     $movies = $article->select('title', 'img', 'head', 'body', 'slug')->bycatslug($slug)->language()->published()->latest()->take(get_setting('pagination_num'))->get();
     return view('components.lists.serials', compact('movies', 'catName'));
 }
Example #7
0
 public function home(Article $article)
 {
     $articles = $article->select('title')->get();
     return view('home')->with('articles', $articles);
 }
Example #8
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $page = Article::findOrFail($id);
     $this->translate_slug = $page->translate_slug;
     $tr = Article::select('lang')->where('lang', '!=', $page->lang)->where(function ($query) {
         return $query->where('slug', '=', $this->translate_slug)->orWhere('translate_slug', '=', $this->translate_slug);
     })->groupBy('id')->get()->toArray();
     $translates = array_pluck($tr, 'lang');
     return view('admin.pages.edit', compact('page', 'translates'));
 }
Example #9
0
 public function similars($limit = 4)
 {
     return Article::select('id', 'title', 'slug', 'image_src')->where(['category_id' => $this->category_id, 'state' => 1])->where('id', '<>', $this->id)->orderByRaw("RANDOM()")->take($limit)->get();
 }
Example #10
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $pages = Article::select('id', 'title', 'lang')->latest()->maincat([1])->paginate(get_setting('pagination_num'));
     return view('admin.pages.index', compact('pages'));
 }
Example #11
0
 public function newsAuthor($author)
 {
     $article = new Article();
     $items = Article::select('id', 'body', 'title', 'head', 'published_at', 'slug', 'author', 'translate_slug', 'img', 'lang')->where('author', $author)->published()->getcat(55)->language()->latest()->take(get_setting('pagination_num'))->get();
     $count = Article::where('author', $author)->published()->getcat(55)->language()->count();
     return view('theme.pages.view.author', compact('items', 'article', 'count', 'author'));
 }
Example #12
0
 function pageWidget($slug, $more = false, $min, $tags = array(), $title = true)
 {
     global $registry;
     $output = '';
     $registry['slug'] = $slug;
     //Cache::pull($registry['slug']);
     $entry = Cache::remember($registry['slug'], $min, function () {
         global $registry;
         return \App\Article::select('slug', 'title', 'body')->where('slug', $registry['slug'])->first();
     });
     if (count($entry) > 0) {
         if ($title == true) {
             $output .= '<div class="rub-title-gray"><a href="/' . $slug . '"><div><h3>' . $entry->title . '</h3></div></a></div>';
         }
         if (count($tags) > 0) {
             $explode = explode('<!-- pagebreak -->', $entry->body);
             if (count($explode) > 0) {
                 foreach ($tags as $key => $i) {
                     $output .= strip_tags($explode[$key]) . '<br>';
                 }
             }
         } else {
             $output .= $entry->body;
         }
         if ($more == true) {
             $output .= ' <a href="/' . $slug . '"><b>' . trans('all.fully') . '...</b></a>';
         }
     }
     return $output;
 }
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $articleId = $this->route('article');
     $isChecked = Article::select('is_checked')->where('id', $articleId)->first();
     return $isChecked->is_checked !== 1;
 }