예제 #1
0
 public function getIndex()
 {
     $user = Auth::user();
     $posts = Post::orderBy('updated_at', 'DESC')->get();
     // Hier später definieren, welche Posts gelesen werden dürfen
     return view('posts.index')->with('posts', $posts);
 }
예제 #2
0
 public function showList()
 {
     $count = Post::count();
     $posts = Post::orderBy('created_at', 'DESC')->take(6)->get();
     return view('list', ['count' => $count, 'posts' => $posts]);
     //будет использоваться list.blade.php
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $search_term = $request->input('search') ? $request->input('search') : '';
     $limit = $request->input('limit') ? $request->input('limit') : 10;
     if ($search_term) {
         $posts = Post::orderBy('id', 'DESC')->where('post', 'LIKE', "%{$search_term}%")->orWhere('title', 'LIKE', "%{$search_term}%")->with(array('User' => function ($query) {
             $query->select('id', 'name');
         }))->select('id', 'title', 'post', 'user_id')->paginate($limit);
         $posts->appends(array('search' => $search_term, 'limit' => $limit));
     } else {
         $posts = Post::orderBy('id', 'DESC')->with(array('User' => function ($query) {
             $query->select('id', 'name');
         }))->select('id', 'title', 'post', 'user_id')->paginate($limit);
         $posts->appends(array('limit' => $limit));
     }
     if (!$posts) {
         return response()->json(['error' => ['message' => 'posts does not exist']], 404);
     }
     return response()->json(['data' => $this->transformCollection($posts)], 200)->setCallback($request->input('callback'));
 }
예제 #4
0
 /**
  * Display a listing of the Post.
  * GET|HEAD /posts
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $offset = $request->page ? $request->page : 1;
     $limit = $request->limit ? $request->limit : 12;
     $category = $request->category;
     $isAllow = $request->isAllow ? $request->isAllow : '';
     $offset = ($offset - 1) * $limit;
     if ($category) {
         if ($isAllow && $isAllow != '') {
             $posts = Post::where('isAllow', $isAllow)->where('category_id', $category)->orderBy('id', 'desc')->offset($offset)->limit($limit)->get();
         } else {
             $posts = Post::where('category_id', $category)->orderBy('id', 'desc')->offset($offset)->limit($limit)->get();
         }
     } else {
         if ($isAllow && $isAllow != '') {
             $posts = Post::where('isAllow', $isAllow)->orderBy('created_at', 'desc')->offset($offset)->limit($limit)->get();
         } else {
             $posts = Post::orderBy('created_at', 'desc')->offset($offset)->limit($limit)->get();
         }
     }
     return response()->json($posts);
 }
예제 #5
0
 public function getHotPost()
 {
     return Post::orderBy('votes', 'desc')->get();
 }
예제 #6
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $posts = Post::orderBy('seen', 'asc')->orderBy('created_at', 'desc')->paginate($this->itemPerPage);
     return view('redac.posts.index', compact('posts'));
 }
예제 #7
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $posts = Post::orderBy('created_at', 'desc')->simplePaginate(10);
     return view('web.post.index', ['posts' => $posts]);
 }
예제 #8
0
 public function getLastPosts()
 {
     return Post::orderBy("created_at", "DESC")->get();
 }