I
I
igordata12020-08-31 20:18:18
Laravel
igordata1, 2020-08-31 20:18:18

How to delete pictures so that they are deleted?

<input type="file"  name="path[]" id="path[]" multiple accept="image/*">
        <div id="for_preview_uploads">
        </div>
        {{--        <div>--}}
        {{--            строка ниже--}}
        {{--        </div>--}}
        <script>
            function resizeImage(img) {
 
                const W = parseInt(img.width / 4);
                const H = parseInt(img.height / 4);
 
                const canvas = document.createElement("canvas");
                canvas.width = W;
                canvas.height = H;
 
                const ctx = canvas.getContext("2d");
                ctx.drawImage(img, 0, 0, W, H);
 
                const resizedImg = new Image();
                resizedImg.src = canvas.toDataURL('image/jpeg', 1);
                //document.body.append(resizedImg);
                document.querySelector("#for_preview_uploads").append(resizedImg);
 
            }
 
            function handleFiles(e) {
 
                for (const file of this.files) {
 
                    const img = document.createElement("img");
                    const reader = new FileReader();
 
                    reader.addEventListener("load", (e) => {
                        img.addEventListener("load", (e) => {
                            resizeImage(img);
                        });
                        img.src = e.target.result;
                    });
 
                    reader.readAsDataURL(file);
 
                }
 
            }
 
            const fileInput = document.getElementById("path[]");
 
            fileInput.addEventListener("change", handleFiles, false);
 
 
        </script>
        @forelse ($product->images as $image)
            <img src="{{$image->path }} " alt="{{$image->title}}">
            <a href="public/uploads/product_images/delete/{{$image->id}}" class="card-link">удалить</a>
        @empty
            Нет фотографий
        @endforelse
 
 
 
    public function destroy(Image $image)
    {
        Storage::disk('public/uploads/product_images/')->delete($image->path);
        $image->delete();
        return redirect()->route('product.edit', ['id' => $image->product_id]);
    }
 
 
 
 
 
 
 
 
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: POST.
http://bossphp.x:8080/products/product/edit_store/39?_method=DELETE&_token=zWq7riCFb5AYEuQUTzvhL3JPoQ5uxnd1lvoO0wsN&authorized_price=32&category_id=19&description=%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5&keywords=%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5&path%5B0%5D=&price=53113&title=%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5%D0%B5
 
 
@forelse ($product->images as $image)
 
            <img src="{{$image->path }} " alt="{{$image->title}}">
            <form action="{{route('images.destroy', $image)}}" method="post">
                @method('DELETE')
                @csrf
                <button type="submit" class="btn btn-danger">Удалить</button>
            </form>
{{--            <a href="public/uploads/product_images/delete/{{$image->id}}" class="card-link">удалить</a>--}}
        @empty
            Нет фотографий
        @endforelse
 
 
public function destroy(Image $image)
    {
        Storage::disk('public')->delete('uploads/product_images/'.$image->path);
//        Storage::disk('public/uploads/product_images/')->delete($image->path);
        $image->delete();
//        return redirect()->route('product.edit', ['id' => $image->product_id]);
    }
 
 
 
 
 
 
Route::get('images/{image}/destroy', '[email protected]')->name('images.destroy');
 
 
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The DELETE method is not supported for this route. Supported methods: GET, HEAD.
http://bossphp.x:8080/images/35/destroy


I can not figure it out, please help if you have time
How to delete pictures so that they are deleted?
Now the 404 error when clicking on the route button
is Route::get("/products/product/delete/{id}", "[email protected]");
So I made a link
to remove

such an error when deleting a picture from a product
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: POST.
bossphp.x:8080/products/product/edit_store/39?_met...
bossphp.x:8080/products/product/edit_store/39?_met...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2020-08-31
@igordata1

Route::get()

The DELETE method is not supported for this route

<a href="public/uploads/product_images/delete/{{$image->id}}"

The GET method is not supported for this route.

Oh, well, I don’t know… What is your zodiac sign? Otherwise, without this, we will not move from the place where we have been marking time for a month.
I rarely say this, but here everything is clear as daylight. Programming is not for you. You can’t cope with an elementary problem for several weeks and, with persistence worthy of a better application, post the same question here without trying to turn on your head at least a little. No answers will help you, unfortunately, try some other hobby (you should definitely forget about making money programming with this approach).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question