Advertisement
MrGoatsy

Untitled

Feb 28th, 2021
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use App\Models\Post;
  6. use Illuminate\Http\Request;
  7.  
  8. class PostController extends Controller {
  9.     public function index() {
  10.         $posts = Post::with('user', 'likes')->orderBy('created_at', 'desc')->paginate(100);
  11.  
  12.         return view('posts.index', [
  13.             'posts' => $posts
  14.         ]);
  15.     }
  16.  
  17.     public function store(Request $request) {
  18.         $this->validate($request, [
  19.             'body'  => [
  20.                 'required',
  21.                 'max:250'
  22.             ],
  23.         ]);
  24.  
  25.         $request->user()->posts()->create([
  26.             'content'   => $request->body
  27.         ]);
  28.  
  29.         return back();
  30.     }
  31.  
  32.     public function destroy(Post $post) {
  33.         //$this->authorize('delete', $post);
  34.         $post->delete();
  35.  
  36.         return back();
  37.     }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement