$input = array();
if ($request->hasFile('company_logo') && $request->company_logo != null) {
$image = $request->file('company_logo');
$destinationPath = 'image/';
$cmp_logo= "image/" . date('Y-m-d-His') . "-" . $image->getClientOriginalName();
$image->move($destinationPath, $cmp_logo);
$input['imagefile'] = "$cmp_logo";
}
Nov 6, 2021
11
Level 2
VueJS + Laravel image upload
So I have this stupid problem, although it should be simple. I have a from with input fields, which I want to sent via axios to laravel backend
VueJS part:
<html>
<input id="company_logo" name="company_logo" type="file" v-on:change="getImageFromInput" />
<script>
user: {
name: {
val: '',
isValid: true
},
address: {
val: '',
isValid: true
},
company_logo: {
val: '',
isValid: true
},
etc.
methods: {
getImageFromInput(event) {
this.user.companyLogo.val = event.target.files[0];
},
async updateUserSettings() {
const updatedData = {
name: this.user.name.val,
address: this.user.address.val,
company_logo: this.user.companyLogo.val,
}
try {
const response = await axios.patch(`http://localhost/api/users/${this.userId}/settings/${this.id}`, updatedData);
...
}
Laravel part:
public function update(Request $request, UserSettings $userSettings, $id)
{
dd(request('address')); // returns what was in address field on vuejs
dd(request('company_logo')); // returns []
I need image file on backend side which is stored on server in /tmp folder, so I can manipulate it. But I am not sure how to fetch the image
Please or to participate in this conversation.