<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...