MrGoatsy

Untitled

Feb 28th, 2021
503
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×