如何在请求中响应message()

时间:2019-08-05 17:16:03

标签: laravel

我需要响应json消息()

class StoryRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required|min:3|max:255|unique:stories',
            'categories' => 'required',
            'image' => 'mimes:jpeg,bmp,png, jpg',
        ];
    }

    public function messages()
    {
        return response()->json([
            'image.mimes' => 'only .jpg, .png, .jpeg',
            'name.required' => 'please name',
            'name.min' => 'min 3',
            'name.max' => 'max 255',
            'name.unique' => 'name unique',
            'categories.required' => 'please choose categories'
        ]);
    }
}

1 个答案:

答案 0 :(得分:0)

尝试一下return redirect('/home')->with('success', 'Password Updated Successfully');