phpist

Untitled

Oct 2nd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use App\Http\Controllers\Admin\CategoriesController;
  6. use Illuminate\Http\Request;
  7. use App\Tag;
  8. use App\Post;
  9. use App\Category;
  10. use Auth;
  11.  
  12.  
  13.  
  14.  
  15.  
  16. class HomeController extends Controller
  17. {
  18. //
  19. public function index()
  20. {
  21. dd($post->author);
  22. // dd(\App::check());
  23. $posts = Post::paginate(2);
  24. $popularPosts = Post::orderBy('views','desc')->take(3)->get();
  25. $featuredPosts = Post::where('is_featured',1)->take(3)->get();
  26. $recentPosts = Post::where('is_featured',1)->take(4)->get();
  27. $categories = Category::all();
  28. // dd($popularPosts);
  29.  
  30. // return view('pages.index', [
  31. // 'posts' => $posts,
  32. // 'popularPosts' => $popularPosts,
  33. // 'featuredPosts' => $featuredPosts,
  34. // 'recentPosts' => $recentPosts,
  35. // 'categories' => $categories
  36. // ]);
  37.  
  38. return view('pages.index')->with('posts', $posts);
  39.  
  40. // return vi ew('pages.index');
  41. }
  42.  
  43. public function show($slug)
  44. {
  45. $post = Post::where('slug', $slug)->firstOrFail();
  46.  
  47. return view('pages.show', compact('post'));
  48. }
  49.  
  50. public function tag($slug)
  51. {
  52. $tag = Tag::where('slug', $slug)->firstOrFail();
  53. // $posts = $tag->post;
  54.  
  55.  
  56. $posts = $tag->posts()->paginate(2);
  57.  
  58. return view('pages.list', ['posts' => $posts]);
  59. }
  60.  
  61. public function category($slug)
  62. {
  63. $category = Category::where('slug', $slug)->firstOrFail();
  64. // $posts = $category->post;
  65.  
  66. $posts = $category->posts()->paginate(2);
  67.  
  68. return view('pages.list', ['posts' => $posts]);
  69. }
  70.  
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment