public function autocomplete() { $term = Request::input('term'); $search = News::where('nTitle', 'LIKE', '%' . $term . '%')->get(); foreach ($search as $item) { $result[] = array('value' => $item->nTitle); } return Response::json($result); }
/** * Get the news entries tagged to me * @param int $limit * @return \Eloquent */ public function news($limit = 5) { if (count($this->newsLatest) >= 1) { return $this->newsLatest; } // get class name that include this file (model name) $parent = str_replace('AppModels', '', stripslashes(static::class)); $rows = DB::select("SELECT news.* FROM {$this->table}\n INNER JOIN news_tag ON news_tag.subject_id = {$this->table}.id\n INNER JOIN news ON news.id = news_tag.news_id\n WHERE {$this->table}.id = ? AND news_tag.subject_type LIKE ?\n GROUP BY news.id\n ORDER BY news.created_at DESC", [$this->id, '%' . $parent]); $news = collect(); // filter active and get photos for entry foreach ($rows as $k => $row) { $item = News::where('id', $row->id)->active()->first(); if ($item) { $item->images; // get the images $news->push($item); } } $this->newsLatest = $news->take($limit); return $this->newsLatest; // old / default way return $this->hasMany(NewsTag::class, 'subject_id', 'id')->where('subject_type', get_class($this))->with('news')->orderBy('created_at', 'DESC'); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $news = News::where('published_at', '<=', Carbon::now())->where('enabled', '=', '1')->orderBy('published_at', 'desc')->paginate(config('news.posts_per_page')); return view('news.index', compact('news')); }
public function frontendShow($id) { $result = News::find($id); if (is_null($result)) { $result = News::where('slug', $id)->get()->first(); } $title = $result->title; $result1 = DB::table('parent_menu')->get(); $siteTitle = Setting::where('name', 'title')->get(); if (count($siteTitle) > 0) { $bah = $siteTitle->first()->value; } else { $bah = 'Website'; } $footer = Setting::where('name', 'footer')->get(); if (count($footer) > 0) { $footer = $footer->first()->value; } else { $footer = '(c) 2015, Ordent, All Right Reserved.'; } return view('frontend.news-show', compact('result', 'title', 'result1', 'footer')); }
public function postDelete(Request $request) { $id = $request->input('id'); $ReturnData = []; if (empty($id)) { $this->error = true; $this->error_message = "Dữ liệu không đúng, vui lòng thử lại"; goto next; } $CheckHasPost = Models\News::where('group_news_id', $id)->count(); if ($CheckHasPost == 0) { try { $rs = Models\Group_news::find($id)->delete(); } catch (Exception $e) { $this->error = true; $this->error_message = "Truy vấn lỗi, vui lòng thử lại"; goto next; } } else { $this->error = true; $this->error_message = "Vui lòng xóa hết bản tin trong chuyên mục này !"; goto next; } $this->error_message = "Thành công"; next: return $this->ResponseData($ReturnData); }