/** * Run the database seeds. * * @return void */ public function run() { $generator = \Faker\Factory::create('vi_VN'); $articleCategories = ['Thị trường nhà đất', 'Dự án căn hộ', 'Đầu tư căn hộ', 'Lời khuyên']; //, 'Vị trí bài viết', 'Slideshow chính', 'Trang chủ', 'Slideshow footer']; $articleCategoryPositionArticles = null; foreach ($articleCategories as $key => $value) { $articleCategory = ArticleCategory::create(['key' => Common::createKeyURL($value), 'parent_id' => is_null($articleCategoryPositionArticles) ? 0 : $articleCategoryPositionArticles->id, 'priority' => $key, 'is_publish' => 1, 'created_by' => 'vankhoektcn', 'updated_by' => 'vankhoektcn']); ArticleCategoryTranslation::create(['article_category_id' => $articleCategory->id, 'locale' => 'vi', 'name' => $value, 'summary' => $value, 'meta_description' => $value, 'meta_keywords' => $value]); if ($value == 'Vị trí bài viết') { $articleCategoryPositionArticles = $articleCategory; } } $articles = ['Giới Thiệu', 'Tuyển Dụng', 'Tài Khoản Giao Dịch']; foreach ($articles as $key => $value) { $article = Article::create(['key' => Common::createKeyURL($value), 'priority' => $key, 'is_publish' => 1, 'created_by' => 'vankhoektcn', 'updated_by' => 'vankhoektcn']); ArticleTranslation::create(['article_id' => $article->id, 'locale' => 'vi', 'name' => $value, 'summary' => $generator->text($maxNbChars = 200), 'content' => $generator->realText($maxNbChars = 1000, $indexSize = 2), 'meta_description' => $generator->text($maxNbChars = 200), 'meta_keywords' => $generator->text($maxNbChars = 200)]); } $categories = ArticleCategory::where('parent_id', '=', 0)->lists('id'); $categories2 = ArticleCategory::where('parent_id', '<>', 0)->lists('id'); for ($i = 0; $i < 3; $i++) { $name = $generator->sentence($nbWords = 6); $key = Common::createKeyURL($name); $article = Article::create(['key' => $key, 'priority' => $i, 'is_publish' => 1, 'created_by' => 'vankhoektcn', 'updated_by' => 'vankhoektcn']); ArticleTranslation::create(['article_id' => $article->id, 'locale' => 'vi', 'name' => $name, 'summary' => $generator->text($maxNbChars = 200), 'content' => $generator->text, 'meta_description' => $generator->text($maxNbChars = 200), 'meta_keywords' => $generator->text($maxNbChars = 200)]); Attachment::create(['entry_id' => $article->id, 'table_name' => 'articles', 'path' => '/uploads/notfound.jpg', 'priority' => 0, 'is_publish' => 1]); $article->categories()->attach($categories->random()); //$article->categories()->attach($categories2->random()); } }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index($categorykey) { $category = ArticleCategory::findByKey($categorykey)->first(); // push all catetory and own child to list $list_sub_categor_id = ArticleCategory::where('parent_id', $category->id)->where('is_publish', 1)->lists('id')->all(); array_push($list_sub_categor_id, $category->id); $articles = Article::whereExists(function ($query) use($list_sub_categor_id) { $query->select(DB::raw(1))->from('article_article_category')->whereRaw('article_article_category.article_id = articles.id')->whereIn('article_category_id', $list_sub_categor_id); })->orderBy('priority')->get(); return view('admin.articles.index', ['articles' => $articles, 'category' => $category]); }
public function getArticlesByCategoryKey($categoryKey = '', $limit = 0) { $articleCategory = ArticleCategory::where('key', $categoryKey)->first(); if (isset($articleCategory) && !is_null($articleCategory)) { if ($limit == 0) { return $articleCategory->articles()->where('is_publish', 1)->orderBy('priority')->orderBy('created_at', 'desc')->get(); } else { return $articleCategory->articles()->where('is_publish', 1)->orderBy('priority')->orderBy('created_at', 'desc')->take($limit)->get(); } } return []; }
public function getLink() { $categorykey = "bai-viet"; $positionParent = ArticleCategory::where('key', 'vi-tri-bai-viet')->first(); if (isset($positionParent)) { $arrayPosId = $positionParent->children->lists('id'); $category = $this->categories()->whereNotIn('id', $arrayPosId)->first(); if (isset($category)) { $categorykey = $category->key; } } $link = route('article', ['categorykey' => $categorykey, 'articlekey' => $this->key]); return $link; }
public function article($articlekey) { $article = Article::where('key', $articlekey)->first(); if ($article != null) { // metadata $site_title = $article->name . ' - ' . Config::findByKey('site_title')->first()->value; SEOMeta::setTitle($site_title); SEOMeta::setDescription($article->meta_description); SEOMeta::addKeyword([$article->meta_keywords]); SEOMeta::addMeta('article:published_time', $article->created_at->toW3CString(), 'property'); if (isset($article->categories->first()->name)) { SEOMeta::addMeta('article:section', $article->categories->first()->name, 'property'); } OpenGraph::setTitle($site_title); OpenGraph::setDescription($article->meta_description); OpenGraph::setUrl(route('article', ['articlekey' => $articlekey])); OpenGraph::addProperty('type', 'article'); OpenGraph::addProperty('locale', app()->getLocale()); OpenGraph::addProperty('locale:alternate', ['vi-vn', 'en-us']); OpenGraph::addImage($article->getFirstAttachment()); OpenGraph::addImage($article->attachments->lists('path')); OpenGraph::addImage(['url' => Image::url($article->getFirstAttachment(), 300, 300, array('crop')), 'size' => 300]); // end metadata $info_category = ArticleCategory::findByKey('thong-tin')->first(); $categories = $info_category->getAllSubCategoryInfo(); $popular_category = ArticleCategory::where('key', 'bai-viet-noi-bat')->first(); $popular_articles = is_null($popular_category) ? null : $popular_category->articles()->where('is_publish', 1)->orderBy('priority')->orderBy('created_at', 'desc')->take(5)->get(); return view('frontend.pages.article', ['article' => $article, 'categories' => $categories, 'popular_articles' => $popular_articles]); } else { abort(404); } }
/** * Reorder items * * @param items list * @return items from @param */ public function getReorder(ReorderRequest $request) { $list = $request->list; $items = explode(",", $list); $order = 1; foreach ($items as $value) { if ($value != '') { ArticleCategory::where('id', '=', $value)->update(array('position' => $order)); $order++; } } return $list; }
/** * Function for changing the Article Type into the Article Type Name. * * @param $value * @return */ public function getCategoryAttribute($value) { $value = ArticleCategory::where('id', $value)->firstOrFail()->name; return $value; }
}); Route::group(['domain' => 'dev.joecurrancodes.dev'], function () { /** * Static or General Page Requests. */ Route::get('/', 'PagesController@index'); Route::get('about', 'PagesController@about'); Route::get('contact', 'PagesController@contact'); Route::post('contact', 'PagesController@contactPost'); Route::get('projects', 'PagesController@projects'); Route::get('dashboard', 'PagesController@dashboard'); Route::get('blog/category', function () { return redirect('blog'); }); Route::get('blog/category/{slug}', function ($slug) { $category = ArticleCategory::where('name', $slug)->first(); if (is_null($category)) { return redirect('blog'); } $articles = Article::where('category', $category->id)->published()->listing()->paginate(4); $pagecode = '8PWLY8FGtvp2nQ5D'; $meta = Meta::where('code', $pagecode)->firstOrFail(); return view('core.article.index', compact('articles', 'meta')); }); /** * Blog or Article Requests. */ Route::resource('blog', 'BlogController'); /** * User Authentication, Registation & Profiles Requests. */
/** * ARTICLE_DETAIL */ public function article_detail($article_id, $article_key) { $article = Article::findOrFail($article_id); if ($article != null) { // metadata $site_title = $article->name . ' - ' . Config::findByKey('site_title')->first()->value; SEOMeta::setTitle($site_title); SEOMeta::setDescription($article->meta_description); SEOMeta::addKeyword([$article->meta_keywords]); SEOMeta::addMeta('article:published_time', $article->created_at->toW3CString(), 'property'); if (isset($article->article_category->name)) { SEOMeta::addMeta('article:section', $article->article_category->name, 'property'); } OpenGraph::setTitle($site_title); OpenGraph::setDescription($article->meta_description); OpenGraph::setUrl($article->getLink()); OpenGraph::addProperty('type', 'article'); OpenGraph::addProperty('locale', app()->getLocale()); OpenGraph::addProperty('locale:alternate', ['vi-vn', 'en-us']); OpenGraph::addImage($article->getThumnail()); OpenGraph::addImage($article->attachments->lists('path')); OpenGraph::addImage(['url' => Image::url($article->getThumnail(), 300, 300, array('crop')), 'size' => 300]); // end metadata $attachments = $article->attachments()->take(5)->get(); $article_category = $article->categories()->first(); $article_categorys = isset($article_category) ? ArticleCategory::where('id', '<>', $article_category->id)->where('is_publish', 1)->orderBy('priority')->orderBy('created_at', 'desc')->get() : ArticleCategory::where('is_publish', 1)->orderBy('priority')->orderBy('created_at', 'desc')->get(); $link = $article->getLink(); $categoryLink = isset($article_category) ? '<li class="active"><a href="' . $article_category->getLink() . '">' . $article_category->name . '</a></li> ' : ''; $breadcrumb = '<ul class="breadcrumb pull-left padl0"> <li class="active"><a href="' . route('homepage') . '">Trang chủ</a></li> <li class="active"><a href="' . route('articles') . '">Tin tức</a></li> ' . $categoryLink . ' <li class=""><a href="' . $link . '">' . $article->name . '</a></li> </ul>'; return view('frontend.sites1.article_detail', ['article' => $article, 'attachments' => $attachments, 'article_category' => $article_category, 'article_categorys' => $article_categorys, 'search_type' => 'article_detail', 'link' => $link, 'breadcrumb' => $breadcrumb]); } else { return view('frontend.sites1.article_detail'); } }
public function search(Request $request) { $validator = Validator::make($request->all(), ['keyword' => 'required']); if ($validator->fails()) { return redirect()->back()->withErrors($validator->errors()); } else { $this->setMetadata('Tìm kiếm'); $aboutus = Article::findByKey('gioi-thieu')->first(); $name = $request->input('keyword'); $limit = Config::findByKey('rows_per_page_article')->first()->value; $articles = Article::whereHas('translations', function ($query) use($name) { $query->where('locale', app()->getLocale())->where('is_publish', 1)->where('name', 'LIKE', '%' . $name . '%')->orderBy('priority')->orderBy('created_at', 'desc'); })->paginate($limit); $popularPostsCategory = ArticleCategory::where('key', 'bai-viet-noi-bat')->first(); $popularPosts = $popularPostsCategory->articles()->where('is_publish', 1)->orderBy('priority')->orderBy('created_at', 'desc')->take(5)->get(); return view('frontend.pages.articles', ['aboutus' => $aboutus, 'articles' => $articles, 'popularPosts' => $popularPosts]); } }