本文整理汇总了PHP中app\models\Article::orderBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::orderBy方法的具体用法?PHP Article::orderBy怎么用?PHP Article::orderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Article
的用法示例。
在下文中一共展示了Article::orderBy方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//banner
$banners = Banner::orderBy('created_at', 'DESC')->take(7)->get();
//最新
$last_articles = Article::with('author')->orderBy('created_time', 'DESC')->take(12)->get();
$hot_articles = Article::orderBy('views', 'DESC')->take(10)->get();
return view('home', compact('banners', 'last_articles', 'hot_articles'));
}
示例2: listArticles
/**
* Lists the inserted articles
* either by id, title or none.
*
* @param int $id
* @param str $title
* @param int $limit
*
* @throws Illuminate\Database\Eloquent\ModelNotFoundException
*
* @return array
**/
public function listArticles($id = null, $title = null, $limit = 20)
{
$query = Article::orderBy('created_at');
if ($id) {
return Article::findOrFail($id);
}
if ($title) {
return $query->where('title', 'LIKE', '%' . $title . '%')->paginate($limit)->items();
}
return $query->paginate($limit)->items();
}
示例3: index
public function index()
{
$collection = Article::orderBy('updated_at')->get();
// dd($collection);
$collection->each(function ($model) {
// var_dump($model->id);
$model = $this->handleModelIndex($model);
});
// dd($collection->toArray());
return $collection;
}
示例4: show
public function show($id)
{
Article::where('id', $id)->increment('views');
//阅读量加1
$article = Article::with(['comments' => function ($query) {
$query->take(10);
}])->find($id);
// dd($article);
$views = Article::where('author_id', $article->author_id)->where('author_type', $article->author_type)->sum('views');
$comments_count = Comment::where('article_id', $id)->count();
$hots = Article::orderBy('views', 'desc')->take(10)->get();
$is_like = false;
$is_collection = false;
$is_follow = false;
if ($this->login_user) {
$is_like = Like::where('user_id', $this->login_user->id)->where('like_type', 'article')->where('like_id', $id)->first();
$is_collection = Collection::where('user_id', $this->login_user->id)->where('collection_type', 'article')->where('collection_id', $id)->first();
$is_follow = DB::table('user_follow')->where('user_id', $this->login_user->id)->where('follow_id', $article->author_id)->first();
}
return view('front.article.index', compact('article', 'views', 'comments_count', 'hots', 'is_like', 'is_collection', 'is_follow'));
}
示例5: all
/**
* display articles
*/
public function all()
{
$articles = Article::orderBy('published_at', 'desc')->simplePaginate(7);
return view('backend.articles', ['articles' => $articles, 'load_js' => 'backend/article.list']);
}
示例6: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('backend.article.index')->with(['items' => Article::orderBy('updated_at', 'desc')->paginate(20)]);
}
示例7: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$posts = Article::orderBy('created_at', 'DESC')->paginate(5);
$data = compact('posts');
return view('blog\\blog', $data);
}
示例8: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$articles = Article::orderBy('date_created', 'DESC')->paginate(20);
return view('admin.articles.index', ['articles' => $articles]);
}
示例9: function
$data = \App\Models\Articles::where('id', '=', 11)->first();
$data->article_title = 'update test -3-.';
$data->feature = true;
$data->save();
}]);
Route::get('delete', ['as' => 'ORM.delete', function () {
$data = \App\Models\Articles::find(2);
$data->delete();
\App\Models\Articles::destroy(19, 20);
}]);
});
Route::get('test', function () {
// $data = \App\Models\Article::find(5);
$data1 = \App\Models\Article::all();
$data2 = \App\Models\Article::where('id', '>', 8);
$data3 = \App\Models\Article::orderBy('id', 'DESC');
dd([$data1, $data2, $data3]);
});
/*
Route::get('hello', function(){
return "Hello World!";
});
Route::get('post/{id}', function($id) {
return "id:".$id;
})->where('id', '[0-9]+');
// route name
Route::get('post2/{id?}', ['as' => 'post2.show', function($id = 0) {
return "id:".$id;
}])->where('id', '[0-9]+');
示例10: index
public function index()
{
$articles = Article::orderBy('published_at', 'desc')->simplePaginate(7);
return view('index', ['articles' => $articles]);
}
示例11: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$articles = Article::orderBy("id", "DESC")->paginate(20);
return view("dashboard.articles.index", compact("articles"));
//->with("message", $message);
}
示例12: index
/**
* Override index here because we want every article in the system
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$articles = Article::orderBy('id', 'desc')->paginate(15);
return view('admin.article.index', compact('articles'));
}
示例13: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$articles = Article::orderBy('id', 'ASC')->paginate(15);
return view('admin/articles/index')->with('articles', $articles);
}
示例14: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$articles = Article::orderBy('created_at', 'desc')->take(10)->get();
return view('articles.index')->with('articles', $articles);
}