как я могу решить эту проблему с помощью скрипта? - PullRequest
0 голосов
/ 26 мая 2020

Я отправляю formData с помощью Ax ios на vue, но Laravel не распознает файлы и возвращает ошибку, как если бы я не установил заголовки

          updateImageList(file) {
                /*console.log(file.size);
                this.showNotification("La imágen no puede ser mayor a 2MB.");*/
                const isLt2M = file.size / 1024 / 1024 < 2;

                if (!isLt2M) {
                    this.showNotification("La imágen no puede ser mayor a 2MB.");
                    this.$refs.upload.clearFiles();
                }
                this.imageList.push(file);
                return isLt2M;
            },
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url;
                this.imageList.push(file);
                this.dialogVisible = true;
            },
            toggle() {
                this.isOpen = !this.isOpen;
            },
            createPost(e) {
                e.preventDefault();
                var body = $("#content-body").val();
                var text = emojione.toImage(body);

                if (!this.validateForm()) {
                    return false;
                }

                this.isCreatingPost = true;

                let formData = new FormData();

                formData.append("user", profile.id);
                formData.append("body", text);

                $.each(this.imageList, function (key, image) {
                    formData.append(`images[${key}]`, image);
                    console.log(key);
                });

                const config = { headers: { 'Content-Type': 'multipart/form-data' } };

                axios.post("/ajax/post/create", formData, config)
                    .then(res => {
                        console.log(res.data);
                        let code = (res.data.status === 1) ? true : false;
                        document.querySelector(".emojionearea-editor").innerHTML = '';

                        if(code === false) {
                            this.status = code;
                            this.showNotification(res.data.msg);
                        }

                        this.isCreatingPost = false;
                        this.imageList = [];
                        this.isOpen = false;
                        /*
                         this.getAllPosts() can be used here as well
                         note: "that" has been assigned the value of "this" at the top
                         to avoid context related issues.
                         */
                        this.$emit("new", 'post');
                    })
                    .catch(error => {
                        console.log(error)
                    });

                this.$refs.upload.clearFiles();
            }

и Laravel code:

$images = $request->images;

foreach($images as $image) {
                    $imageName = $image->getClientOriginalName();
                    $image->move(public_path($path, $imageName));

                    Image::create([
                        'url' => $imageName,
                        'imageable_id' => $post->id,
                        'imageable_type' => 'App\Post',
                    ]);
                }

и возвращает эту ошибку, я не знаю, что еще делать. Я изменил заголовки, и ничего ... он работал, но больше ничего ... извините за мой Engli sh

capture

просьба помочь с этим спасибо

...