Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

uniqueginun's avatar

Inertia js return error message when submitting inertia form

I have inertia component that submits inertia form :

data() {
        return {
            form: this.$inertia.form({
                name: '',
                contractor: '',
                city: '',
                start: '',
                end: '',
                cost: '',
                paid: '',
                percentage: '',
                status: '',
                editing: false
            }),
            bootstrap: null
        }
    },
    methods: {
        openModal(project = null) {
            this.bootstrap = $('#projectsModal');
            this.form.reset();
            this.form.errors = {};

            if (project) {
                const { id, name } = project
                this.form.name = name
                this.form.editing = id
            }

            this.bootstrap.modal('toggle');

            setTimeout(() => {
                this.$refs.name.focus()
            }, 1000)
        },

        makeAction() {
            this.form.post(route('projects.store'), {
                preserveScroll: true,
                onSuccess: () => {
                    this.bootstrap.modal('toggle');
                    this.form.reset();
                },
            })
        }
    },

here's my controller

/**
     * Store a newly created resource in storage.
     *
     * @param  ProjectRequest  $request
     * @return Response
     */
    public function store(ProjectRequest $request)
    {
        try {
            $request->persist();
            return Redirect::route('projects.index');
        } catch (\Exception $exception) {
            Log::error($exception->getMessage());

            ValidationException::withMessages([
                'name' => 'error happened in our end!'
            ]);
        }
    }

I'm intentionally throwing an exception so the catch block throw validation exception and when that happen inertia should show those errors. but this is not happening instead it shows me an empty modal. even though when a true validation exception happen it shows me that error.

0 likes
1 reply

Please or to participate in this conversation.