151 lines
7.5 KiB
PHP
151 lines
7.5 KiB
PHP
@extends('layouts.app')
|
|
|
|
@section('content')
|
|
<div class="container-fluid">
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3 class="card-title">{{ isset($promotion) ? 'Edit Promotion' : 'Create New Promotion' }}</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
@if(session('error'))
|
|
<div class="alert alert-danger">{{ session('error') }}</div>
|
|
@endif
|
|
|
|
<form action="{{ isset($promotion) ? route('promotions.update', $promotion['id']) : route('promotions.store') }}"
|
|
method="POST"
|
|
enctype="multipart/form-data">
|
|
@csrf
|
|
@if(isset($promotion))
|
|
@method('PUT')
|
|
@endif
|
|
|
|
<div class="form-group">
|
|
<label for="title">Title</label>
|
|
<input type="text"
|
|
class="form-control @error('title') is-invalid @enderror"
|
|
id="title"
|
|
name="title"
|
|
value="{{ old('title', isset($promotion) ? $promotion['title'] : '') }}"
|
|
required>
|
|
@error('title')
|
|
<div class="invalid-feedback">{{ $message }}</div>
|
|
@enderror
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="description">Description</label>
|
|
<textarea class="form-control @error('description') is-invalid @enderror"
|
|
id="description"
|
|
name="description"
|
|
rows="4"
|
|
required>{{ old('description', isset($promotion) ? $promotion['description'] : '') }}</textarea>
|
|
@error('description')
|
|
<div class="invalid-feedback">{{ $message }}</div>
|
|
@enderror
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="image">Promotion Image</label>
|
|
<div class="custom-file">
|
|
<input type="file"
|
|
class="custom-file-input @error('image') is-invalid @enderror"
|
|
id="image"
|
|
name="image"
|
|
accept="image/*"
|
|
{{ !isset($promotion) ? 'required' : '' }}>
|
|
<label class="custom-file-label" for="image">Choose file</label>
|
|
</div>
|
|
@error('image')
|
|
<div class="invalid-feedback">{{ $message }}</div>
|
|
@enderror
|
|
@if(isset($promotion) && $promotion['image_url'])
|
|
<div class="mt-2">
|
|
<img src="{{ $promotion['image_url'] }}"
|
|
alt="Current promotion image"
|
|
class="img-thumbnail"
|
|
style="max-height: 200px;">
|
|
</div>
|
|
@endif
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="form-group">
|
|
<label for="start_date">Start Date</label>
|
|
<input type="date"
|
|
class="form-control @error('start_date') is-invalid @enderror"
|
|
id="start_date"
|
|
name="start_date"
|
|
value="{{ old('start_date', isset($promotion) ? \Carbon\Carbon::parse($promotion['start_date'])->format('Y-m-d') : '') }}"
|
|
required>
|
|
@error('start_date')
|
|
<div class="invalid-feedback">{{ $message }}</div>
|
|
@enderror
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="form-group">
|
|
<label for="end_date">End Date</label>
|
|
<input type="date"
|
|
class="form-control @error('end_date') is-invalid @enderror"
|
|
id="end_date"
|
|
name="end_date"
|
|
value="{{ old('end_date', isset($promotion) ? \Carbon\Carbon::parse($promotion['end_date'])->format('Y-m-d') : '') }}"
|
|
required>
|
|
@error('end_date')
|
|
<div class="invalid-feedback">{{ $message }}</div>
|
|
@enderror
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<div class="custom-control custom-switch">
|
|
<input type="checkbox"
|
|
class="custom-control-input"
|
|
id="is_active"
|
|
name="is_active"
|
|
value="1"
|
|
{{ old('is_active', isset($promotion) ? $promotion['is_active'] : true) ? 'checked' : '' }}>
|
|
<label class="custom-control-label" for="is_active">Active</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<button type="submit" class="btn btn-primary">
|
|
{{ isset($promotion) ? 'Update' : 'Create' }} Promotion
|
|
</button>
|
|
<a href="{{ route('promotions.index') }}" class="btn btn-secondary">Cancel</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@endsection
|
|
|
|
@push('scripts')
|
|
<script>
|
|
$(document).ready(function() {
|
|
// Update file input label with selected filename
|
|
$('.custom-file-input').on('change', function() {
|
|
let fileName = $(this).val().split('\\').pop();
|
|
$(this).next('.custom-file-label').addClass("selected").html(fileName);
|
|
});
|
|
|
|
// Validate end date is after start date
|
|
$('#end_date').on('change', function() {
|
|
let startDate = new Date($('#start_date').val());
|
|
let endDate = new Date($(this).val());
|
|
|
|
if (endDate < startDate) {
|
|
alert('End date must be after start date');
|
|
$(this).val('');
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
@endpush
|