Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Laravel: Foreign id does not have default value

/**
     * Store a newly created resource in storage.
     *
     * @param  IlluminateHttpRequest  $request
     * @return IlluminateHttpResponse
     */
    public function store(Request $request)
    {
        //
        $validator = Validator::make($request->all(), [
            'preferred_day' => [
                'required',
                Rule::in('wednesday','friday'),
            ],
            'preferred_time' => 'required|date_format:h:i:s',
            'goals' => 'required|min:10',
        ]);

        if ($validator->fails()) {
            return response()->json($validator->errors(), 422);
        }

        $validated = $validator->validated();

        $detail = ClientDetail::create($validated);
        return new ClientDetailResource($detail);
    }
 
PREVIOUS NEXT
Tagged: #Foreign #id #default
ADD COMMENT
Topic
Name
5+2 =