SHARE
TWEET

Untitled

a guest Jan 24th, 2020 71 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\Framework\FrameworkController;
  6. use App\Framework\Nodes\PostNode;
  7. use App\Post;
  8. use App\User;
  9. use Illuminate\Http\Request;
  10. use Illuminate\Support\Facades\DB;
  11.  
  12. class PostController extends FrameworkController
  13. {
  14.     public function getNodeClass()
  15.     {
  16.         return PostNode::class;
  17.     }
  18.  
  19.     public function store(Request $request)
  20.     {
  21.         $request = $request->all();
  22.  
  23.         $response = DB::transaction(static function() use ($request){
  24.             try {
  25.                 $post = new Post();
  26.                 $post->title = $request['title'];
  27.                 $post->content = $request['content'];
  28.                 $post->user()->associate(User::find(1));
  29.                 $post->save();
  30.                 $post->groups()->sync($request['group_id']);
  31.                 return ['id' => $post->id ];
  32.             }
  33.             catch (\Exception $exception) {
  34.                 var_dump(null);
  35.             }
  36.         });
  37.  
  38.         return $response ?? response()->json(['error' => 'Not Found.'], 404);
  39.     }
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top