samedi 3 octobre 2020

nuxt.js how upload image using laravel back end API

i am struck in image uploading help me i learned lots of things in nuxt.js but i am struck in image uploading.

how to make image uploading form in nuxt.js

i Created laravel API for image uploading.

my Router

Route::group(['middleware' => 'auth:api'], function() {
Route::post('/Employeeregister', 'EMPLOYEE_API\RegisterController@register')->name('Employeeregister');

}); 

CONTROLLER CODE

 public function imageUploadPost(Request $request)
    {
        $request->validate([
            'name' =>  'required | string',
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        ]);
  
        $imageName = time().'.'.$request->image->extension();  
   
        $request->image->move(public_path('images'), $imageName);
   
        return back()
            ->with('success','You have successfully upload image.')
            ->with('image',$imageName);
   
    }

MY Nuxt code

<template>
    <v-row justify="center">
        <v-col cols="12" sm="6">
            <form @submit.prevent="submit">
                <v-card ref="form" >
                    <v-card-text>
                        <h3 class="text-center">Register</h3>
                        <v-divider class="mt-3"></v-divider>
                        <v-col cols="12" sm="12">
                            <v-text-field v-model.trim="form.name" type="text" label="Full Name" solo autocomplete="off"></v-text-field>
                        </v-col>
                    </v-card-text>
                    <v-card-actions>
                        <v-spacer></v-spacer>
                        <div class="text-center">
                            <v-btn rounded type="submit" color="primary" dark>Register</v-btn>
                        </div>
                    </v-card-actions>
                </v-card>
            </form>
        </v-col>
    </v-row>
</template>
< script >
  export default {
    middleware: ['guest'],
    data() {
      return {
        form: {
          name: '',
        }
      }
    },
  } <
  /script>


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3cSx2xc
via IFTTT

Aucun commentaire:

Enregistrer un commentaire