Skip to content
Advertisement

How to upload file using laravel vue api?

i’m trying to make a form with the ability to upload files using form

i’m able to store string, int data but i’m a bit lost with the way that i need to provide for the controller and the view

this is the add template:

JavaScript

this is the database table:

JavaScript

controller:

JavaScript

model:

JavaScript

app:

JavaScript

i can provide more code if necessary

the current code is working and storing in database but the only problem is uploading a file

Advertisement

Answer

Firstly you need to call onchnage function like @change="onChange($event). Secondly you need to put code in onchange function like below. onChange(event) {this.category.file = event.target.file;} And last you need to use FormData and pass Header in api in create function like below.

EDIT

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement