Laravel Inertia not returning validation errors - Hack The Tech - Latest News related to Computer and Technology

logo

Get Daily Latest News related to Computer and Technology and hack the world.

Friday, June 4, 2021

demo-image

Laravel Inertia not returning validation errors

Inertia Does not Returning any validation errors

Here is my controller code

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request)
{
    Request::validate([
        'firstName' => ['required', 'string', 'max:100'],
        'lastName'  => ['required', 'string', 'max:100'],
        'shopName'  => ['required', 'string', 'max:100'],
        'email'     => ['required', 'email', Rule::unique('vendors', 'email')],
        'mobile'    => ['required', 'string'],
        'password'  => ['required', 'min:6', 'max:12', 'confirmed']
    ]);

    Vendor::create($request->validated());

    return Redirect::route('vendors.create')->with('success', 'Vendor created.');
}

Here is my vue component code

export default {
name: "Create Vendor",
props: {
    auth: Object,
    errors: Object,
},
data() {
    return {
        form: this.$inertia.form({
            firstName: null,
            lastName: null,
            shopName: null,
            email: null,
            mobile: null,
            password: null,
            password_confirmation: null,
        }),
    };
},

methods: {
    store() {
        return this.form.post(this.route("vendors.store"));
    },
},

};

But after submit the error object is always empty

Note: I have also set the HandleInertiaRequest middleware.

enter image description here



source https://stackoverflow.com/questions/67826997/laravel-inertia-not-returning-validation-errors

No comments:

Post a Comment