@igordata1

Как сделать удаление картинок чтоб они удалялись?

<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', 'AdminProductsController@destroy')->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


Не могу разобраться, помогите пожалуйста, если у вас есть время
Как сделать удаление картинок чтоб они удалялись?
Сейчас ошибка 404 при нажатии на кнопку
роут такой Route::get("/products/product/delete/{id}", "AdminProductsController@destroy");
Так сделал ссылку
удалить

такая ошибка при удалении картинки у товара
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...
  • Вопрос задан
  • 452 просмотра
Решения вопроса 1
alexey-m-ukolov
@alexey-m-ukolov Куратор тега Laravel
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.


Ой, ну не знаю… У вас какой знак зодиака? А то без этого мы не сдвинемся с места, на котором топчемся который месяц.

Я редко такое говорю, но тут всё ясно как белый день. Программирование — это не ваше. Вы с элементарной проблемой не можете справиться несколько недель и с упорством достойным лучшего применения постите сюда один и тот же вопрос не пытаясь включить голову хотя бы немного. Никакие ответы вам не помогут, к сожалению, попробуйте какое-то другое хобби (о том, чтобы зарабатывать программированием вам точно стоит забыть с таким подходом).
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы