121 lines
6.3 KiB
PHP
121 lines
6.3 KiB
PHP
@extends('layouts.app')
|
|
|
|
@section('page_title', 'Add Promotion')
|
|
|
|
@section('content')
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="mb-0 fw-bold text-dark">Add New Promotion</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
@if (session('error'))
|
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
|
{{ session('error') }}
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
@endif
|
|
@if (session('success'))
|
|
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
|
{{ session('success') }}
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
@endif
|
|
<form action="{{ route('promotions.store') }}" method="POST" enctype="multipart/form-data">
|
|
@csrf
|
|
<div class="mb-3">
|
|
<label for="title" class="form-label">Title</label>
|
|
<input type="text" class="form-control" id="title" name="title" value="{{ old('title') }}" required maxlength="100">
|
|
@error('title')
|
|
<div class="text-danger">{{ $message }}</div>
|
|
@enderror
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="type" class="form-label">Type</label>
|
|
<select class="form-select" id="type" name="type" required>
|
|
@foreach ($promoTypes as $key => $type)
|
|
<option value="{{ $type }}" data-id="{{ $key }}" {{ old('type') == $type ? 'selected' : '' }}>{{ $type }}</option>
|
|
@endforeach
|
|
</select>
|
|
<input type="hidden" name="promo_type" id="promo_type" value="{{ old('promo_type') }}">
|
|
@error('type')
|
|
<div class="text-danger">{{ $message }}</div>
|
|
@enderror
|
|
@error('promo_type')
|
|
<div class="text-danger">{{ $message }}</div>
|
|
@enderror
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="description" class="form-label">Description</label>
|
|
<textarea class="form-control" id="description" name="description" required>{{ old('description') }}</textarea>
|
|
@error('description')
|
|
<div class="text-danger">{{ $message }}</div>
|
|
@enderror
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="image" class="form-label">Image</label>
|
|
<input type="file" class="form-control" id="image" name="image" accept="image/*" required>
|
|
@error('image')
|
|
<div class="text-danger">{{ $message }}</div>
|
|
@enderror
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="start_date" class="form-label">Start Date</label>
|
|
<input type="date" class="form-control" id="start_date" name="start_date" value="{{ old('start_date') }}" required>
|
|
@error('start_date')
|
|
<div class="text-danger">{{ $message }}</div>
|
|
@enderror
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="end_date" class="form-label">End Date</label>
|
|
<input type="date" class="form-control" id="end_date" name="end_date" value="{{ old('end_date') }}" required>
|
|
@error('end_date')
|
|
<div class="text-danger">{{ $message }}</div>
|
|
@enderror
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="status" class="form-label">Status</label>
|
|
<select class="form-select" id="status" name="status" required>
|
|
<option value="On Going" {{ old('status') == 'On Going' ? 'selected' : '' }}>On Going</option>
|
|
<option value="Done" {{ old('status') == 'Done' ? 'selected' : '' }}>Done</option>
|
|
</select>
|
|
@error('status')
|
|
<div class="text-danger">{{ $message }}</div>
|
|
@enderror
|
|
</div>
|
|
<div class="mb-3 form-check">
|
|
<input type="checkbox" class="form-check-input" id="is_toppromotion" name="is_toppromotion" value="1" {{ old('is_toppromotion') ? 'checked' : '' }}>
|
|
<label class="form-check-label" for="is_toppromotion">Is Top Promotion</label>
|
|
@error('is_toppromotion')
|
|
<div class="text-danger">{{ $message }}</div>
|
|
@enderror
|
|
</div>
|
|
<div class="mb-3 form-check">
|
|
<input type="checkbox" class="form-check-input" id="is_gps" name="is_gps" value="1" {{ old('is_gps') ? 'checked' : '' }}>
|
|
<label class="form-check-label" for="is_gps">Is GPS-Based</label>
|
|
@error('is_gps')
|
|
<div class="text-danger">{{ $message }}</div>
|
|
@enderror
|
|
</div>
|
|
<input type="hidden" name="station_uuid" value="[]">
|
|
<button type="submit" class="btn btn-primary">Add Promotion</button>
|
|
<a href="{{ route('promotions') }}" class="btn btn-secondary ms-2">Cancel</a>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.getElementById('type').addEventListener('change', function() {
|
|
const selectedOption = this.options[this.selectedIndex];
|
|
const promoTypeId = selectedOption.getAttribute('data-id');
|
|
document.getElementById('promo_type').value = promoTypeId;
|
|
});
|
|
|
|
// Set initial promo_type value on page load
|
|
window.addEventListener('load', function() {
|
|
const typeSelect = document.getElementById('type');
|
|
const selectedOption = typeSelect.options[typeSelect.selectedIndex];
|
|
const promoTypeId = selectedOption.getAttribute('data-id');
|
|
document.getElementById('promo_type').value = promoTypeId;
|
|
});
|
|
</script>
|
|
@endsection |