app/Http/Controllers/PostsController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $rules = [
            'content' => 'required|max:1000'
        ];
        $validator = Validator::make($request->all(), $rules);
        if($validator->fails()){
            return response()->json($validator->errors(), 400);
        }
        $post = Post::create($request->all());
        $post->user_id = Auth::user()['id'];
        $post->save();
        return response()->json($post, 201);
    }
public function store ( Request $ request ) { $ rules = [ 'content' => 'required|max:1000' ] ; $ validator = Validator :: make ( $ request -> all ( ) , $ rules ) ; if ( $ validator -> fails ( ) ) { return response ( ) -> json ( $ validator -> errors ( ) , 400 ) ; } $ post = Post :: create ( $ request -> all ( ) ) ; $ post -> user_id = Auth :: user ( ) [ 'id' ] ; $ post -> save ( ) ; return response ( ) -> json ( $ post , 201 ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .