Skip to content

Instantly share code, notes, and snippets.

@59naga
Created October 6, 2019 04:29
Show Gist options
  • Save 59naga/068f06a90f92cda7cfd9715b545eab3b to your computer and use it in GitHub Desktop.
Save 59naga/068f06a90f92cda7cfd9715b545eab3b to your computer and use it in GitHub Desktop.
/// https://bi-82v3955.slack.com/archives/GMMK5SREG/p1570329882000900?thread_ts=1569770241.007500&cid=GMMK5SREG
        try {
            $validator = Validator::make(
                $request->all(),
                [
                    'password' => Rule::requiredIf($request->authority_id >= 1),
                    'name' => 'unique:staffs',
                ],
                [
                    'password.required' => 'パスワードを入力してください',
                    'name.unique' => 'その名前はすでに登録されています',
                ]
            )->validate();
        } catch (\Exception $error) {
            $status = $error->status;
            $errors = collect($error->errors())->flatten()->all();
            return response()->json(compact('status', 'errors'), $status);
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment