public function blog($title) { $selectedPostType = addslashes($title); $postCategoryName = ArticleTypes::where(['seo_url' => $selectedPostType])->first(); if (!$postCategoryName) { return redirect('/'); } $articles = Article::with('type')->whereHas('type', function ($query) use($selectedPostType) { $query->where(['seo_url' => $selectedPostType]); })->with('author')->paginate(5); $popular = Article::with('type')->whereHas('type', function ($query) use($selectedPostType) { $query->where(['seo_url' => $selectedPostType]); })->with('author')->orderBy('viewed')->take(5)->get()->toArray(); //$popular = Article::with(['author','type'])->where(['seo_url' => $title])->orderBy('viewed')->take(5)->get()->toArray(); return view('blog.bloghome', ['articles' => $articles, 'popular' => $popular, 'postCategoryName' => $postCategoryName]); }
public function create() { $article = new Article(); if (Request::isMethod('post')) { $rules = array('title' => 'required', 'intro' => 'required', 'content' => 'required', 'type_id' => 'required'); $validator = Validator::make(Input::all(), $rules); // process the login if ($validator->fails()) { return Redirect::to('admin/post/create/')->withErrors($validator)->withInput(); } else { if (empty(Input::get('seo_url'))) { $seo_url = Helper::seo_url(Input::get('title')); } else { $seo_url = $Input::get('seo_url'); } // store $article->title = Input::get('title'); $article->intro = Input::get('intro'); $article->content = Input::get('content'); $article->user_id = Auth::id(); $article->type_id = Input::get('type_id'); $article->display_author_name = Input::get('display_author_name'); $article->seo_url = $seo_url; $article->viewed = 0; $article->status = Input::get('enabled') == 'on' ? 1 : 0; $article->save(); // redirect Session::flash('message', 'New post has been created successfully'); return Redirect::to('/admin/post'); } } $types = ArticleTypes::lists('name', 'id'); return view('admin.post.create')->with(['article' => $article, 'types' => $types]); }