1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

LaravelでAPIのレスポンスにバリデーションの内容をのせる方法

Last updated at Posted at 2020-12-18

やり方

public function test(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'mail' => 'required',
        ]);
        
        // バリデーションエラーの場合は'errors'で内容と箇所を返す
        if ($validator->fails()) {
            return response()->json([
                'errors' => $validator->errors()
            ], 200);
        }

        // 成功
        // 何か処理...
    }
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?