Files
click-erp/app/Http/Controllers/HolidaysController.php
2026-04-16 14:22:04 +00:00

105 lines
2.9 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models;
use Session;
use Illuminate\Support\Arr;
use App\Jobs\SendHolidayEmailAlerts;
use App\Http\Requests;
use Carbon\Carbon;
class HolidaysController extends Controller{
public function getHolidayDetails(){
$upcoming_hodidays = Models\NationalHoliday::whereRaw("(month(event_date) >= month(curdate()))")->whereRaw("(year(event_date) >= year(curdate()))")->orderBy('event_date', 'ASC')->take(15)->get();
if ($upcoming_hodidays->isEmpty() == false) {
dispatch(new SendHolidayEmailAlerts($upcoming_hodidays->toArray()));
}
}
public function index(){
// Using pagination is generally better than get() for lists
$holidays = Models\NationalHoliday::orderBy('event_date', 'asc')->paginate(15);
dd($holidays);
return view('holidays.index', compact('holidays'));
}
/**
* Show the form for creating a new holiday.
*/
public function create(){
return view('holidays.create');
}
/**
* Store a newly created holiday in the database.
*/
public function store(Request $request)
{
$validatedData = $request->validate([
'name' => 'required|string|max:191',
'country' => 'required|string|max:191',
'event_date' => 'required|date',
]);
Models\NationalHoliday::create($validatedData);
return redirect()->route('holidays.index')
->with('success', 'Holiday created successfully.');
}
/**
* Display the specified holiday.
*/
public function show($id)
{
$holiday = Models\NationalHoliday::findOrFail($id);
return view('holidays.show', compact('holiday'));
}
/**
* Show the form for editing the specified holiday.
*/
public function edit($id)
{
$holiday = Models\NationalHoliday::findOrFail($id);
return view('holidays.edit', compact('holiday'));
}
/**
* Update the specified holiday in the database.
*/
public function update(Request $request, $id)
{
$validatedData = $request->validate([
'name' => 'required|string|max:191',
'country' => 'required|string|max:191',
'event_date' => 'required|date',
]);
$holiday = Models\NationalHoliday::findOrFail($id);
$holiday->update($validatedData);
return redirect()->route('holidays.index')
->with('success', 'Holiday updated successfully.');
}
/**
* Remove the specified holiday from the database.
*/
public function destroy($id)
{
$holiday = Models\NationalHoliday::findOrFail($id);
$holiday->delete();
return redirect()->route('holidays.index')
->with('success', 'Holiday deleted successfully.');
}
}