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

Stingoosha's avatar

Laravel + Inertia How to upload file?

Hi, guys! In my project i want to upload file using such template (without < />)


template
	form @submit.prevent="submit"
		label for="photo" value="Photo"
        input name="photo" type="file"
		button type="submit" :class="{ 'opacity-25': form.processing }" :disabled="form.processing"
        	Add photo
        /button
	/form
/template
script
	export default {
		data() {
            return {
                form: this.$inertia.form({
                    photo: '',
                })
            }
        },
        methods: {
            submit() {
                this.form.post(this.route("photo.store"))
            }
        },
	}
/script

And in controller i get


dd($request->photo) // "C:\fakepath\filename.jpg

Could You please prompt how to get $request->photo of UploadedFile class to save it in normal way?

0 likes
4 replies
koramit's avatar
koramit
Best Answer
Level 9

Your file input does not get a file. Try this,

<input type="file" @input="form.photo = $event.target.files[0]" />

3 likes

Please or to participate in this conversation.