Files
besttechfrom.eu/resources/views/products/edit.blade.php
T
2026-02-06 14:56:56 +02:00

153 lines
7.4 KiB
PHP

@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-10">
<div class="card">
<div class="card-header">
<h3 class="mb-0">Edit Product</h3>
</div>
<div class="card-body">
<form method="POST" action="{{ route('products.update', $product) }}" enctype="multipart/form-data">
@csrf
@method('PUT')
<!-- Title -->
<div class="mb-3">
<label for="title" class="form-label">Product Title <span class="text-danger">*</span></label>
<input type="text"
class="form-control @error('title') is-invalid @enderror"
id="title"
name="title"
value="{{ old('title', $product->title) }}"
required
maxlength="255">
@error('title')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<!-- Description -->
<div class="mb-3">
<label for="description" class="form-label">Description <span class="text-danger">*</span></label>
<textarea class="form-control @error('description') is-invalid @enderror"
id="description"
name="description"
rows="5"
required>{{ old('description', $product->description) }}</textarea>
@error('description')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<!-- Website URL -->
<div class="mb-3">
<label for="website_url" class="form-label">Website URL <span class="text-danger">*</span></label>
<input type="url"
class="form-control @error('website_url') is-invalid @enderror"
id="website_url"
name="website_url"
value="{{ old('website_url', $product->website_url) }}"
required>
@error('website_url')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<!-- Category -->
<div class="mb-3">
<label for="category_id" class="form-label">Category <span class="text-danger">*</span></label>
<select class="form-select @error('category_id') is-invalid @enderror"
id="category_id"
name="category_id"
required>
<option value="">Select a category...</option>
@foreach($categories as $category)
<option value="{{ $category->id }}"
{{ old('category_id', $product->category_id) == $category->id ? 'selected' : '' }}>
{{ $category->name }}
</option>
@endforeach
</select>
@error('category_id')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<!-- Current Thumbnail -->
@if($product->thumbnail_url)
<div class="mb-3">
<label class="form-label">Current Thumbnail:</label>
<div>
<img src="{{ $product->thumbnail_url }}" alt="{{ $product->title }}" style="max-width: 300px; max-height: 300px;" class="img-thumbnail">
</div>
</div>
@endif
<!-- New Thumbnail -->
<div class="mb-3">
<label for="thumbnail" class="form-label">
{{ $product->thumbnail_url ? 'Replace Thumbnail' : 'Product Thumbnail' }}
</label>
<input type="file"
class="form-control @error('thumbnail') is-invalid @enderror"
id="thumbnail"
name="thumbnail"
accept="image/*">
@error('thumbnail')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
<small class="form-text text-muted">JPEG, PNG, or GIF, max 2MB.</small>
</div>
<!-- Image Preview -->
<div class="mb-3" id="imagePreview" style="display: none;">
<label class="form-label">New Preview:</label>
<div>
<img id="preview" src="#" alt="Thumbnail preview" style="max-width: 300px; max-height: 300px;" class="img-thumbnail">
</div>
</div>
<!-- Submit Button -->
<div class="d-flex justify-content-between">
<a href="{{ route('products.show', $product) }}" class="btn btn-secondary">Cancel</a>
<button type="submit" class="btn btn-primary">Update Product</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@push('scripts')
<script>
document.getElementById('thumbnail').addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
document.getElementById('preview').src = e.target.result;
document.getElementById('imagePreview').style.display = 'block';
}
reader.readAsDataURL(file);
} else {
document.getElementById('imagePreview').style.display = 'none';
}
});
</script>
@endpush
@endsection