本文整理汇总了PHP中app\Article::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::where方法的具体用法?PHP Article::where怎么用?PHP Article::where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Article
的用法示例。
在下文中一共展示了Article::where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: forUser
/**
* Get all of the articles for a given user.
**
*
* @return mixed
*/
public function forUser()
{
if ($this->user->is_admin) {
return $this->article->all()->sortBy('created_at');
}
return $this->article->where('user_id', $this->user->id)->orderBy('created_at', 'asc')->get();
}
示例2: getIndex
/**
* Return all all articles
*/
public function getIndex(Request $request)
{
$articles = Article::where('active', 1);
/**
* Filter by category
*/
if ($request->has('category')) {
$filter_category = $request->get('category');
$category = Category::find($filter_category);
// if there is no category with this name
if (!$category) {
return response()->json(['code' => '404', 'message' => 'There is no category with this id'], 404);
}
// if category is exists
$articles = $category->articles();
}
/**
* Filter by order
*/
if ($request->has('order')) {
$fitler_order = $request->get('order');
if ($fitler_order == 'desc' || $fitler_order == 'asc') {
$articles->orderBy('views', $fitler_order);
}
}
return response()->json(['code' => '200', 'data' => $articles->get()], 200);
}
示例3: show
public function show($slug)
{
// $article = Article::with('authors', 'tags', 'pictures', 'videos', 'category')->findOrFail($id);
$article = Article::where(['articles.slug' => $slug])->with('authors', 'tags', 'pictures', 'videos', 'category')->first();
$pictures = $article->picturesArray;
return view('article.show', compact('article', 'pictures'));
}
示例4: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($slug)
{
$article = Article::where('slug', $slug)->firstOrFail();
$articleSide = DB::select("select title, slug, image_lead\n from articles\n WHERE ID !='{$article->id}' limit 5;");
$googlePhrahes = Google::limit(30)->orderBy('id', 'DESC')->get();
return view('article', compact('article', 'articleSide', 'googlePhrahes'));
}
示例5: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
parent::boot($router);
\Route::bind('articleslug', function ($value) {
return \App\Article::where('slug', $value)->with('user')->with('writer')->with('screenshot.image')->firstOrFail();
});
}
示例6: showArticle
public function showArticle($id)
{
$article = Article::findOrFail($id);
$news = Article::where('id', '>', $article->id)->orderBy('id', 'DESC')->take(NEW_OLD_ARTICLE);
$olds = Article::where('id', '<', $article->id)->orderBy('id', 'DESC')->take(NEW_OLD_ARTICLE);
return view('frontend.articles.main')->with(compact('news', 'article', 'olds'));
}
示例7: index
public function index(Article $article)
{
// $articles = $article->getArticles();
$articles = Article::where('active', '=', 1)->where('published_at', '<=', Carbon::now())->latest('published_at')->simplePaginate(4);
$articles->setPath('articles');
return view('articles.articles')->with('articles', $articles);
}
示例8: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
$router->bind('article', function ($slug) {
return Article::where('slug', $slug)->firstOrFail();
});
parent::boot($router);
}
示例9: index
public function index()
{
$choosenLang = \Session::get('locale');
$tags = Tag::where('lang', '=', $choosenLang)->get();
$articles = Article::where('lang', '=', $choosenLang)->paginate(2);
return view('index', compact('articles', 'tags'));
}
示例10: getArticle
public function getArticle($cate, $arti)
{
$arti = substr($arti, 0, -5);
//cắt chuối ".html" cuối article alias
$category = Category::where("category_alias", $cate)->first();
//lấy category đầu tiên có alias bằng tham số category alias
$listCategory = Category::all(["id", "category_alias", "category_name"])->toArray();
$allArticles = Article::all(["id", "title", "alias", "summary", "content", "image", "category_id", "author", "created_date"])->where('category_id', $category["id"])->toArray();
//lấy tất cả bài viết trong category
if ($category != null) {
$message = "";
$category_name = $category["category_name"];
if (count($allArticles) == 0) {
$message = 'Không có bài viết nào.';
} else {
$article = Article::where("alias", $arti)->first();
if ($article != null) {
$relateArticles = Article::where('category_id', $category["id"])->where("id", '!=', $article["id"])->orderBy('created_date', 'desc')->get()->take(2)->toArray();
return view('front.blog.article', compact('listCategory', 'relateArticles', 'message', 'category_name', 'article', 'mess'));
} else {
$message = "Không tìm thấy bài viết phù hợp";
return view('front.blog.error', compact('listCategory', 'message', 'category_name'));
}
}
return view('blog.index', compact('listCategory', 'message', 'category_name'));
}
}
示例11: detail
public function detail($slug, Request $request)
{
$slug = Input::get('slug');
$articleModel = new Article();
$article = $articleModel->where('slug', $slug)->firstOrFail();
return $article;
}
示例12: article
public function article($categorykey, $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', ['categorykey' => $categorykey, '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
return view('frontend.sites.article', compact('article'));
} else {
return view('errors.404');
}
}
示例13: Home
public function Home()
{
$flash = Event::where('start_date', '<=', new \Datetime())->where('end_date', '>=', new \Datetime())->orderBy('id', 'desc')->take(1)->get()->first();
$articles = Article::where('id', '!=', isset($flash) ? $flash->article->id : 0)->orderBy('publish_at', 'desc')->orderBy('id', 'desc')->take(5)->get();
$ffttNews = FFTTNew::orderBy('date', 'desc')->take(3)->get();
return view('front.home', array('articles' => $articles, 'NewsFlash' => $flash, 'ffttNews' => $ffttNews));
}
示例14: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot(Router $router)
{
$router->bind('article', function ($id) {
return \App\Article::where('slug', $id)->first();
});
parent::boot($router);
}
示例15: index
public function index($username)
{
$articles = Article::where('user_id', '=', auth()->user()->id)->orderBy('created_at', 'desc')->get();
$categories = Category::all();
$tags = Tag::all();
return view('articles.new')->with(['articles' => $articles, 'categories' => $categories, 'tags' => $tags]);
}