Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6. use App\Http\Requests;
  7. use App\User;
  8. use App\Post;
  9. use App\Category;
  10. use Mail;
  11. use Session;
  12.  
  13. class PostsController extends Controller {
  14.  
  15.     public function getIndex() {
  16.     $posts = Post::orderBy('created_at', 'desc')->paginate(5);
  17.         return view('front.posts.index')->withPosts($posts);
  18.     }
  19.    
  20.     /**
  21.      * Display the specified resource.
  22.      *
  23.      * @param  int  $id
  24.      * @return \Illuminate\Http\Response
  25.      */
  26.     public function show($id, $slug = '')
  27.     {
  28.         $post = Post::findOrFail($id);
  29.  
  30.         if ($slug !== $post->slug) {
  31.             return redirect()->to($post->slug, 301);
  32.         }
  33.  
  34.         return view('front.posts.show')->withPost($post);
  35.     }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement