87 lines
2.3 KiB
PHP
87 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\HrmAddon\App\Http\Controllers\Api;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
use Modules\HrmAddon\App\Models\Holiday;
|
|
|
|
class HolidayController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$holidays = Holiday::with('branch:id,name')->where('business_id', auth()->user()->business_id)->latest()->get();
|
|
|
|
return response()->json([
|
|
'message' => __('Data fetched successfully.'),
|
|
'data' => $holidays,
|
|
]);
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
$data = Holiday::where('business_id', auth()->user()->business_id)->findOrFail($id);
|
|
|
|
return response()->json([
|
|
'message' => __('Data fetched successfully.'),
|
|
'data' => $data,
|
|
]);
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$request->validate([
|
|
'name' => 'required|string|max:255',
|
|
'start_date' => 'required|date',
|
|
'end_date' => 'required|date',
|
|
'description' => 'nullable|string',
|
|
]);
|
|
|
|
$data = Holiday::create($request->except('business_id') + [
|
|
'business_id' => auth()->user()->business_id
|
|
]);
|
|
|
|
return response()->json([
|
|
'message' => __('Data saved successfully.'),
|
|
'data' => $data,
|
|
]);
|
|
}
|
|
|
|
public function update(Request $request, string $id)
|
|
{
|
|
$request->validate([
|
|
'name' => 'nullable|string|max:255',
|
|
'start_date' => 'required|date',
|
|
'end_date' => 'required|date',
|
|
'description' => 'nullable|string',
|
|
]);
|
|
|
|
$holiday = Holiday::where('business_id', auth()->user()->business_id)->findOrFail($id);
|
|
|
|
$holiday->update($request->except('business_id'));
|
|
|
|
return response()->json([
|
|
'message' => __('Data saved successfully.'),
|
|
'data' => $holiday,
|
|
]);
|
|
}
|
|
|
|
public function destroy(string $id)
|
|
{
|
|
$holiday = Holiday::where('business_id', auth()->user()->business_id)->findOrFail($id);
|
|
|
|
if (!$holiday) {
|
|
return response()->json([
|
|
'message' => __('Data not found.'),
|
|
], 404);
|
|
}
|
|
|
|
$holiday->delete();
|
|
|
|
return response()->json([
|
|
'message' => __('Data deleted successfully.'),
|
|
]);
|
|
}
|
|
|
|
}
|