Beispiel #1
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
 }
Beispiel #2
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index($current_page)
 {
     $current_page = $current_page ? $current_page : 1;
     $current_page = $current_page - 1;
     $page = 10;
     //echo $current_page*$page;exit;
     $post = Post::leftJoin('websites', 'posts.website', '=', 'websites.websites_id')->leftJoin('projects', 'posts.project', '=', 'projects.projects_id')->orderby('posts_id', 'desc')->offset($current_page * $page)->limit($page);
     $posts['data'] = $post->get();
     $posts['count'] = Post::count();
     $posts['pageSize'] = $page;
     return response()->json($posts);
 }
 public function index()
 {
     $postsPerPage = $this->_config('posts_on_index');
     // Way 1
     // Define which get method to use to fetch Posts by checking ACL
     // Use that function and the Model's logic to get those posts.
     $unpub = $this->user->hasAccess('blog read unpublished');
     $method = $unpub ? 'newest' : 'newestPublished';
     $posts = models\Post::$method($postsPerPage);
     // The quick 'n dirty //
     $page = Options::one($_GET, 'page', 1, false);
     $start = ($page - 1) * $postsPerPage;
     $conditions = $unpub ? '1' : 'is_published = 1';
     $posts = models\Post::all($conditions . ' ORDER BY created_on DESC LIMIT ' . $start . ', ' . $postsPerPage . '');
     // Don't do it! //
     // Way 2
     // Define the difference in conditions here (instead of in the Model)
     $conditions = $unpub ? '' : array('is_published' => true);
     $numAllPosts = models\Post::count($conditions);
     // Way 3
     // A third way would be a combination like this:
     /*
     			$access = $this->user->hasAccess('blog read unpublished');
     			$posts = model\Post::postsByAccess($access, $this->_config('posts_on_index'));
     */
     // That way you can check access in the Controller and have fetch logic in the Model
     $messages = Session::messages();
     $canCreatePosts = $this->user->hasAccess('blog create posts');
     return get_defined_vars();
     // view will be rendered by row\Controller->_post_action
     return $this->_display(__METHOD__, get_defined_vars(), !$this->AJAX);
     // view will be rendered by Output->display
     return $this->_display(get_defined_vars());
     // view will be rendered by Output->display
 }
Beispiel #4
0
 public function getNumPosts()
 {
     return \app\models\Post::count(array('author_id' => $this->user_id));
 }
 public function numPosts()
 {
     return Post::count(array('category_id' => $this->category_id));
 }
 /**
  * Dashboard index.
  *
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function index()
 {
     $postsCount = Post::count();
     $commentsCount = Comment::whereSeen(0)->count();
     return view('back.index', compact('postsCount', 'commentsCount'));
 }