jeudi 30 novembre 2017

storing file path using laravel and component vuejs2

i work with an interface with backend laravel and frontend vuejs2 i used a component to register a new record in my database it work perfectly with the input type text but with input type file i don't know how to get the path and store it using function store of laravel

component vuejs

template

  <input type="file" @change="processFile($event)"  id='image' v-model="article.image" >

</div>
 <div class="modal-footer">

<button type="button" @click="CreateArticle">Enregistrer</button>
 </div>

vue Script

<script>
    export default {
        data(){
            return {
                articles:[],

                article:{
                    image:'',
                },
          }
        },


        methods:{


            CreateArticle:function(){

                axios.post(window.Laravel.url+'/addArticle',this.article)

                .then( response => {
                    if(response.data.etat){

                        this.article.id=response.data.id;
                        this.articles.unshift(this.article);
                        this.article={
                                    id:0,
                                    image:'',

                                }     
                    }

                    })

                  .catch(error => {


                    });
            },

           processFile(event) {
            this.someData = event.target.files[0],

  },
        },

    }
</script>

Controller function

public function addArticle(Request $request){

        $art=new Article();
        if($request->hasFile('image')){
         $art->img=$request->image->store('images');

       }

        $art->save();

    return Response()->json(['etat'=>true,'id'=>$art->id]);

}

route:

Route::post('/addArticle','CategorieController@addArticle');



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2iqdSXs
via IFTTT

Aucun commentaire:

Enregistrer un commentaire