Example #1
0
 /**
  * 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'));
 }
Example #2
0
 /**
  * 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();
 }
Example #3
0
 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;
 }
Example #4
0
 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'));
 }
Example #5
0
 /**
  * display articles
  */
 public function all()
 {
     $articles = Article::orderBy('published_at', 'desc')->simplePaginate(7);
     return view('backend.articles', ['articles' => $articles, 'load_js' => 'backend/article.list']);
 }
Example #6
0
 /**
  * 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)]);
 }
 /**
  * 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);
 }
 /**
  * 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]);
 }
Example #9
0
        $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]+');
Example #10
0
 public function index()
 {
     $articles = Article::orderBy('published_at', 'desc')->simplePaginate(7);
     return view('index', ['articles' => $articles]);
 }
Example #11
0
 /**
  * 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);
 }
 /**
  * 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'));
 }
 /**
  * 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);
 }
 /**
  * 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);
 }