app/Http/Controllers/RequestsController.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 = [
            'requested_user' => 'required'
        ];
        $validator = Validator::make($request->all(), $rules);
        if($validator->fails()){
            return response()->json($validator->errors(), 400);
        }
        $request = UserRequest::create($request->all());
        $request->user_id = Auth::user()['id'];
        $request->requested_user = $request['requested_user'];
        $request->save();
        return response()->json($request, 201);
    }
public function store ( Request $ request ) { $ rules = [ 'requested_user' => 'required' ] ; $ validator = Validator :: make ( $ request -> all ( ) , $ rules ) ; if ( $ validator -> fails ( ) ) { return response ( ) -> json ( $ validator -> errors ( ) , 400 ) ; } $ request = UserRequest :: create ( $ request -> all ( ) ) ; $ request -> user_id = Auth :: user ( ) [ 'id' ] ; $ request -> requested_user = $ request [ 'requested_user' ] ; $ request -> save ( ) ; return response ( ) -> json ( $ request , 201 ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .