migrate to gtea from bistbucket
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Frontend\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\RequestSanitizerTrait;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\Frontend\Http\Requests\AboutUs\AboutUsStoreRequest;
|
||||
use Modules\Frontend\Http\Requests\AboutUs\AboutUsUpdateRequest;
|
||||
use Modules\Frontend\Repositories\AboutUsRepository;
|
||||
|
||||
class AboutUsController extends Controller
|
||||
{
|
||||
use RequestSanitizerTrait;
|
||||
|
||||
public function __construct(private AboutUsRepository $faq) {}
|
||||
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->getAll(request()->all()),
|
||||
'AboutUs has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function store(AboutUsStoreRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->create($request->all()),
|
||||
'AboutUs has been created successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->getById($id),
|
||||
'AboutUs has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function update(AboutUsUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->update($id, $this->getUpdateRequest($request)),
|
||||
'AboutUs has been updated successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->delete($id),
|
||||
'AboutUs has been deleted successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Frontend\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\RequestSanitizerTrait;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\Frontend\Http\Requests\AcademicImage\AcademicImageStoreRequest;
|
||||
use Modules\Frontend\Http\Requests\AcademicImage\AcademicImageUpdateRequest;
|
||||
use Modules\Frontend\Repositories\AcademicImageRepository;
|
||||
|
||||
class AcademicImageController extends Controller
|
||||
{
|
||||
use RequestSanitizerTrait;
|
||||
|
||||
public function __construct(private AcademicImageRepository $academicImage) {}
|
||||
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->academicImage->getAll(request()->all()),
|
||||
'AcademicImages has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function store(AcademicImageStoreRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->academicImage->create($request->all()),
|
||||
'AcademicImages has been created successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->academicImage->getById($id),
|
||||
'AcademicImages has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function update(AcademicImageUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->academicImage->update($id, $this->getUpdateRequest($request)),
|
||||
'AcademicImages has been updated successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->academicImage->delete($id),
|
||||
'AcademicImages has been deleted successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Frontend\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\RequestSanitizerTrait;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\Frontend\Http\Requests\Banner\BannerStoreRequest;
|
||||
use Modules\Frontend\Http\Requests\Banner\BannerUpdateRequest;
|
||||
use Modules\Frontend\Repositories\BannerRepository;
|
||||
|
||||
class BannerController extends Controller
|
||||
{
|
||||
use RequestSanitizerTrait;
|
||||
|
||||
public function __construct(private BannerRepository $banner) {}
|
||||
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->banner->getAll(request()->all()),
|
||||
'Banner has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function store(BannerStoreRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->banner->create($request->all()),
|
||||
'Banner has been created successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->banner->getById($id),
|
||||
'Banner has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function update(BannerUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->banner->update($id, $this->getUpdateRequest($request)),
|
||||
'Banner has been updated successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
$banner = $this->banner->getById($id);
|
||||
if (! $banner) {
|
||||
return $this->responseError([], 'Restaurant Not Found');
|
||||
}
|
||||
if ($banner->image) {
|
||||
fileRemover('banners/', $banner->image);
|
||||
}
|
||||
|
||||
return $this->responseSuccess(
|
||||
$this->banner->delete($id),
|
||||
'Banner has been deleted successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Frontend\Http\Controllers\API;
|
||||
|
||||
use App\Helper\RestaurantHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Booking\Models\Floor;
|
||||
use Modules\Booking\Models\Hotel;
|
||||
use Modules\Booking\Models\Room;
|
||||
use Modules\Booking\Models\RoomAvailability;
|
||||
use Modules\Booking\Models\RoomBlock;
|
||||
use Modules\Booking\Models\RoomType;
|
||||
|
||||
class BookingFrontendController extends Controller
|
||||
{
|
||||
/**
|
||||
* Get Hotels with filters, search, sorting, pagination
|
||||
*/
|
||||
public function getHotels(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
$filters = $request->all();
|
||||
$query = Hotel::query()->where('restaurant_id', $restaurantId);
|
||||
|
||||
// Search
|
||||
if (! empty($filters['search'])) {
|
||||
$search = $filters['search'];
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'LIKE', "%$search%")
|
||||
->orWhere('code', 'LIKE', "%$search%");
|
||||
});
|
||||
}
|
||||
|
||||
// Status filter
|
||||
if (isset($filters['status'])) {
|
||||
$query->where('status', $filters['status']);
|
||||
}
|
||||
|
||||
return $this->applySortingPagination($query, $filters, ['id', 'name', 'status', 'created_at'], 'Hotels fetched successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Floors with filters, search, sorting, pagination
|
||||
*/
|
||||
public function getFloors(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
$filters = $request->all();
|
||||
$query = Floor::query()->with('hotel:id,name')->where('restaurant_id', $restaurantId);
|
||||
|
||||
if (! empty($filters['search'])) {
|
||||
$query->where('name', 'LIKE', "%{$filters['search']}%");
|
||||
}
|
||||
|
||||
if (! empty($filters['hotel_id'])) {
|
||||
$query->where('hotel_id', $filters['hotel_id']);
|
||||
}
|
||||
|
||||
return $this->applySortingPagination($query, $filters, ['id', 'name', 'created_at'], 'Floors fetched successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Room Types
|
||||
*/
|
||||
public function getRoomTypes(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
$filters = $request->all();
|
||||
$query = RoomType::query()->where('restaurant_id', $restaurantId);
|
||||
|
||||
if (! empty($filters['search'])) {
|
||||
$query->where('name', 'LIKE', "%{$filters['search']}%");
|
||||
}
|
||||
|
||||
return $this->applySortingPagination($query, $filters, ['id', 'name', 'created_at'], 'Room types fetched successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Rooms
|
||||
*/
|
||||
public function getRooms(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
$filters = $request->all();
|
||||
$query = Room::with(['hotel:id,name', 'floor:id,name', 'roomType:id,name'])
|
||||
->where('restaurant_id', $restaurantId);
|
||||
|
||||
if (! empty($filters['search'])) {
|
||||
$search = $filters['search'];
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('room_number', 'LIKE', "%$search%")
|
||||
->orWhere('room_code', 'LIKE', "%$search%")
|
||||
->orWhereHas('hotel', fn ($q) => $q->where('name', 'LIKE', "%$search%"))
|
||||
->orWhereHas('floor', fn ($q) => $q->where('name', 'LIKE', "%$search%"));
|
||||
});
|
||||
}
|
||||
|
||||
if (! empty($filters['hotel_id'])) {
|
||||
$query->where('hotel_id', $filters['hotel_id']);
|
||||
}
|
||||
if (! empty($filters['floor_id'])) {
|
||||
$query->where('floor_id', $filters['floor_id']);
|
||||
}
|
||||
if (! empty($filters['room_type_id'])) {
|
||||
$query->where('room_type_id', $filters['room_type_id']);
|
||||
}
|
||||
if (isset($filters['status'])) {
|
||||
$query->where('status', $filters['status']);
|
||||
}
|
||||
|
||||
return $this->applySortingPagination($query, $filters, ['id', 'room_number', 'status', 'created_at'], 'Rooms fetched successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Room Availabilities
|
||||
*/
|
||||
public function getRoomAvailabilities(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
$filters = $request->all();
|
||||
$query = RoomAvailability::with(['room:id,room_number,hotel_id'])
|
||||
->where('restaurant_id', $restaurantId);
|
||||
|
||||
if (! empty($filters['room_id'])) {
|
||||
$query->where('room_id', $filters['room_id']);
|
||||
}
|
||||
if (! empty($filters['hotel_id'])) {
|
||||
$query->where('hotel_id', $filters['hotel_id']);
|
||||
}
|
||||
if (! empty($filters['date_from']) && ! empty($filters['date_to'])) {
|
||||
$query->whereBetween('date', [$filters['date_from'], $filters['date_to']]);
|
||||
}
|
||||
|
||||
return $this->applySortingPagination($query, $filters, ['date', 'room_id', 'hotel_id'], 'Room availabilities fetched successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Room Blocks
|
||||
*/
|
||||
public function getRoomBlocks(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
$filters = $request->all();
|
||||
$query = RoomBlock::with(['room:id,room_number,hotel_id'])
|
||||
->where('restaurant_id', $restaurantId);
|
||||
|
||||
if (! empty($filters['room_id'])) {
|
||||
$query->where('room_id', $filters['room_id']);
|
||||
}
|
||||
if (! empty($filters['hotel_id'])) {
|
||||
$query->where('hotel_id', $filters['hotel_id']);
|
||||
}
|
||||
if (! empty($filters['start_date']) && ! empty($filters['end_date'])) {
|
||||
$query->where(function ($q) use ($filters) {
|
||||
$q->whereBetween('start_date', [$filters['start_date'], $filters['end_date']])
|
||||
->orWhereBetween('end_date', [$filters['start_date'], $filters['end_date']]);
|
||||
});
|
||||
}
|
||||
|
||||
return $this->applySortingPagination($query, $filters, ['start_date', 'room_id', 'hotel_id'], 'Room blocks fetched successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract restaurant_id from X-Domain header
|
||||
*/
|
||||
private function getRestaurantIdFromHeader(Request $request): mixed
|
||||
{
|
||||
$domain = $request->header('X-Domain');
|
||||
if (! $domain) {
|
||||
return $this->responseError([], 'Domain header is missing.', 400);
|
||||
}
|
||||
|
||||
$restaurantResponse = RestaurantHelper::getRestaurantIdByDomain($domain);
|
||||
if (! $restaurantResponse['status']) {
|
||||
return $this->responseError([], $restaurantResponse['error'], 404);
|
||||
}
|
||||
|
||||
return $restaurantResponse['restaurant_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Reusable function for sorting & pagination
|
||||
*/
|
||||
private function applySortingPagination($query, array $filters, array $allowedSortColumns, string $message): JsonResponse
|
||||
{
|
||||
$sortBy = $filters['sort_by'] ?? $allowedSortColumns[0];
|
||||
$sortOrder = $filters['sort_order'] ?? 'desc';
|
||||
if (! in_array($sortBy, $allowedSortColumns)) {
|
||||
$sortBy = $allowedSortColumns[0];
|
||||
}
|
||||
|
||||
$query->orderBy($sortBy, $sortOrder);
|
||||
|
||||
$perPage = $filters['per_page'] ?? 15;
|
||||
|
||||
return $this->responseSuccess($query->paginate($perPage), $message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Frontend\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Frontend\Http\Requests\CMSSection\CMSSectionStoreRequest;
|
||||
use Modules\Frontend\Http\Requests\CMSSection\CMSSectionUpdateRequest;
|
||||
use Modules\Frontend\Repositories\CMSSectionRepository;
|
||||
|
||||
class CMSSectionController extends Controller
|
||||
{
|
||||
public function __construct(private CMSSectionRepository $repo) {}
|
||||
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess($this->repo->getAll(request()->all()), 'CMSSection has been fetched successfully.');
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function store(CMSSectionStoreRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess($this->repo->create($request->all()), 'CMSSection has been created successfully.');
|
||||
} catch (\Illuminate\Database\QueryException $exception) {
|
||||
return $this->responseError([], 'Database error: '.$exception->getMessage());
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess($this->repo->getById($id), 'CMSSection has been fetched successfully.');
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update(CMSSectionUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess($this->repo->update($id, $request->all()), 'CMSSection has been updated successfully.');
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess($this->repo->delete($id), 'CMSSection has been deleted successfully.');
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function updateOrder(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'sections' => ['required', 'array'],
|
||||
'sections.*.id' => ['required', 'integer', 'exists:c_m_s_sections,id'],
|
||||
'sections.*.serial' => ['required', 'integer'],
|
||||
]);
|
||||
|
||||
foreach ($request->sections as $item) {
|
||||
DB::table('c_m_s_sections')
|
||||
->where('id', $item['id'])
|
||||
->update(['serial' => $item['serial']]);
|
||||
}
|
||||
|
||||
return $this->responseSuccess([], 'CMS Section order updated successfully.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Frontend\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Frontend\Models\Contact;
|
||||
|
||||
class ContactController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$query = Contact::query()->select('id', 'email');
|
||||
|
||||
// --- Filter by email ---
|
||||
if ($request->has('email') && $request->email) {
|
||||
$query->where('email', 'like', '%'.$request->email.'%');
|
||||
}
|
||||
|
||||
// --- Sorting ---
|
||||
$sortBy = $request->get('sort_by', 'email'); // default sort column
|
||||
$sortOrder = $request->get('sort_order', 'asc'); // asc or desc
|
||||
$query->orderBy($sortBy, $sortOrder);
|
||||
|
||||
// --- Pagination ---
|
||||
$perPage = (int) $request->get('perPage', 15); // default 15
|
||||
$contacts = $query->paginate($perPage);
|
||||
|
||||
return $this->responseSuccess(
|
||||
$contacts,
|
||||
'Contacts fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Frontend\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\Frontend\Http\Requests\Coupon\CouponStoreRequest;
|
||||
use Modules\Frontend\Http\Requests\Coupon\CouponUpdateRequest;
|
||||
use Modules\Frontend\Repositories\CouponRepository;
|
||||
|
||||
class CouponController extends Controller
|
||||
{
|
||||
public function __construct(private CouponRepository $repo) {}
|
||||
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess($this->repo->getAll(request()->all()), 'Coupon has been fetched successfully.');
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function store(CouponStoreRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess($this->repo->create($request->all()), 'Coupon has been created successfully.');
|
||||
} catch (\Illuminate\Database\QueryException $exception) {
|
||||
return $this->responseError([], 'Database error: '.$exception->getMessage());
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess($this->repo->getById($id), 'Coupon has been fetched successfully.');
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update(CouponUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess($this->repo->update($id, $request->all()), 'Coupon has been updated successfully.');
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess($this->repo->delete($id), 'Coupon has been deleted successfully.');
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Frontend\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\RequestSanitizerTrait;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\Frontend\Http\Requests\Faq\FaqStoreRequest;
|
||||
use Modules\Frontend\Http\Requests\Faq\FaqUpdateRequest;
|
||||
use Modules\Frontend\Repositories\FaqQuestionRepository;
|
||||
|
||||
class FaqQuestionController extends Controller
|
||||
{
|
||||
use RequestSanitizerTrait;
|
||||
|
||||
public function __construct(private FaqQuestionRepository $faqQuestion) {}
|
||||
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faqQuestion->getAll(request()->all()),
|
||||
'Faq has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function store(FaqStoreRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faqQuestion->create($request->all()),
|
||||
'Faq has been created successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faqQuestion->getById($id),
|
||||
'Faq has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function update(FaqUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faqQuestion->update($id, $this->getUpdateRequest($request)),
|
||||
'Faq has been updated successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faqQuestion->delete($id),
|
||||
'Faq has been deleted successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,976 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Frontend\Http\Controllers\API;
|
||||
|
||||
use App\Helper\RestaurantHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Modules\Authentication\Models\Restaurant;
|
||||
use Modules\Authentication\Models\RestaurantImageSAASSetting;
|
||||
use Modules\Authentication\Models\RestaurantImageSetting;
|
||||
use Modules\Authentication\Models\User;
|
||||
use Modules\Authentication\Services\RestaurantSetupService;
|
||||
use Modules\Frontend\Http\Requests\Contact\ContactStoreRequest;
|
||||
use Modules\Frontend\Http\Requests\Onboarding\OnboardingStoreRequest;
|
||||
use Modules\Frontend\Models\AboutUs;
|
||||
use Modules\Frontend\Models\AcademicImage;
|
||||
use Modules\Frontend\Models\Banner;
|
||||
use Modules\Frontend\Models\CMSSection;
|
||||
use Modules\Frontend\Models\Contact;
|
||||
use Modules\Frontend\Models\Coupon;
|
||||
use Modules\Frontend\Models\FaqQuestion;
|
||||
use Modules\Frontend\Models\MobileAppSection;
|
||||
use Modules\Frontend\Models\Onboarding;
|
||||
use Modules\Frontend\Models\OurHistory;
|
||||
use Modules\Frontend\Models\Policy;
|
||||
use Modules\Frontend\Models\ReadyToJoinUs;
|
||||
use Modules\Frontend\Models\Testimonial;
|
||||
use Modules\Frontend\Models\Theme;
|
||||
use Modules\Frontend\Models\WhyChooseUs;
|
||||
use Modules\Restaurant\Models\Customer;
|
||||
use Modules\Restaurant\Models\FoodCategory;
|
||||
use Modules\Restaurant\Models\FoodItem;
|
||||
use Modules\Restaurant\Models\MenuCategory;
|
||||
use Modules\Restaurant\Models\ReservationSetting;
|
||||
use Modules\Restaurant\Models\ReservationUnavailable;
|
||||
use Modules\Restaurant\Models\RestaurantSchedule;
|
||||
use Modules\Restaurant\Models\Table;
|
||||
use Modules\Restaurant\Repositories\ReservationRepository;
|
||||
|
||||
class FrontendController extends Controller
|
||||
{
|
||||
public function __construct(private ReservationRepository $reservationRepository) {}
|
||||
|
||||
public function publicFoodCategories(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
$categoryLimit = 100;
|
||||
$productLimit = 100;
|
||||
try {
|
||||
$categories = FoodCategory::where('restaurant_id', $restaurantId)
|
||||
->where('status', 1)
|
||||
->limit($categoryLimit)
|
||||
->with(['foodItems' => function ($q) use ($restaurantId, $productLimit) {
|
||||
$q->where('restaurant_id', $restaurantId)
|
||||
->with('variants', 'defaultVariant')
|
||||
->orderBy('id', 'desc')
|
||||
->limit($productLimit);
|
||||
}])
|
||||
->get();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$categories,
|
||||
'Categories with food items fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function foodItems(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$query = FoodItem::with([
|
||||
'category',
|
||||
'variants',
|
||||
'defaultVariant',
|
||||
'availabilities',
|
||||
'addons',
|
||||
])
|
||||
->where('restaurant_id', $restaurantId);
|
||||
|
||||
// 🔥 Filter by status
|
||||
if ($request->has('status')) {
|
||||
$query->where('status', $request->status);
|
||||
} else {
|
||||
$query->where('status', 1); // default active
|
||||
}
|
||||
|
||||
// 🔥 Filter by category
|
||||
if ($request->filled('category_id')) {
|
||||
$query->where('category_id', $request->category_id);
|
||||
}
|
||||
|
||||
if ($request->filled('menu_category_id')) {
|
||||
$query->where('menu_category_id', $request->menu_category_id);
|
||||
}
|
||||
|
||||
if ($request->filled('menu_section_id')) {
|
||||
$query->where('menu_section_id', $request->menu_section_id);
|
||||
}
|
||||
|
||||
// 🔥 Chef Special filter
|
||||
if ($request->filled('chef_special')) {
|
||||
$query->chefSpecial($request->chef_special);
|
||||
}
|
||||
|
||||
// 🔥 Popular Item filter
|
||||
if ($request->filled('popular')) {
|
||||
$query->popular($request->popular);
|
||||
}
|
||||
|
||||
// 🔥 Search by name, slug, description
|
||||
if ($request->filled('search')) {
|
||||
$search = $request->search;
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
// 🔥 Sorting
|
||||
$sortBy = $request->get('sort_by', 'id'); // default sort by id
|
||||
$sortOrder = $request->get('sort_order', 'desc'); // default desc
|
||||
$query->orderBy($sortBy, $sortOrder);
|
||||
|
||||
// 🔥 Pagination
|
||||
$perPage = (int) $request->get('per_page', 15);
|
||||
$data = $query->paginate($perPage);
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'Food items fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function foodDetails(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = FoodItem::where('slug', $request->slug)
|
||||
->where('restaurant_id', $restaurantId)
|
||||
->where('status', 1)
|
||||
->with('category', 'variants', 'defaultVariant', 'availabilities', 'addons', 'reviews')
|
||||
->first();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'FoodItems has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function menuCategoryWiseSections(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId; // invalid restaurant header
|
||||
}
|
||||
|
||||
try {
|
||||
$categories = MenuCategory::with([
|
||||
'menuSections' => function ($q) use ($restaurantId) {
|
||||
$q->where('restaurant_id', $restaurantId)
|
||||
->where('status', 1)
|
||||
->with(['foodItems' => function ($q2) {
|
||||
$q2->where('status', 1)
|
||||
->with(['variants', 'defaultVariant']);
|
||||
}]);
|
||||
},
|
||||
'foodItems' => function ($q) {
|
||||
$q->where('status', 1)
|
||||
->with(['variants', 'defaultVariant']);
|
||||
},
|
||||
])
|
||||
->where('restaurant_id', $restaurantId)
|
||||
->where('status', 1)
|
||||
->get(['id', 'name']);
|
||||
|
||||
return $this->responseSuccess($categories, 'Menu fetched successfully.');
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function chefs(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = User::where('restaurant_id', $restaurantId)
|
||||
->where('status', 1)
|
||||
->where('role_id', 7)
|
||||
->get();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'Chef has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function tables(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = Table::where('restaurant_id', $restaurantId)
|
||||
->where('status', 1)
|
||||
->get();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'Table has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function tableReservation(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$validated = $request->validate([
|
||||
'table_id' => 'required|integer|exists:tables,id',
|
||||
'name' => 'nullable|string|max:255',
|
||||
'phone' => 'nullable|string|max:255',
|
||||
'email' => 'nullable|string|email|max:255',
|
||||
'reservation_date' => 'required|date',
|
||||
'start_time' => 'required|date_format:H:i',
|
||||
// 'end_time' => 'required|date_format:H:i|after:start_time',
|
||||
'people_count' => 'required|integer|min:1',
|
||||
'status' => 'nullable|in:booked,free,upcoming,cancelled',
|
||||
'note' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$validated['restaurant_id'] = $restaurantId;
|
||||
|
||||
// --- Handle customer ---
|
||||
$customerId = null;
|
||||
if (! empty($validated['email']) || ! empty($validated['phone'])) {
|
||||
$customer = Customer::firstOrCreate(
|
||||
[
|
||||
'restaurant_id' => $restaurantId,
|
||||
'email' => $validated['email'],
|
||||
'phone' => $validated['phone'],
|
||||
],
|
||||
[
|
||||
'name' => $validated['name'] ?? 'Guest',
|
||||
'email' => $validated['email'] ?? null,
|
||||
'phone' => $validated['phone'] ?? null,
|
||||
'restaurant_id' => $restaurantId,
|
||||
]
|
||||
);
|
||||
|
||||
$customerId = $customer->id;
|
||||
}
|
||||
|
||||
$validated['customer_id'] = $customerId;
|
||||
|
||||
// --- Start & end time logic ---
|
||||
$start = $validated['start_time'];
|
||||
$end = $validated['end_time'] ?? null;
|
||||
// Parse start time
|
||||
$startTime = Carbon::createFromFormat('H:i', $start);
|
||||
// If end time is not provided, set +30 mins
|
||||
if (! $end) {
|
||||
$endTime = $startTime->copy()->addMinutes(30);
|
||||
$validated['end_time'] = $endTime->format('H:i');
|
||||
} else {
|
||||
$endTime = Carbon::createFromFormat('H:i', $end);
|
||||
// Ensure minimum 30 mins
|
||||
if ($endTime->diffInMinutes($startTime) < 30) {
|
||||
$endTime = $startTime->copy()->addMinutes(30);
|
||||
$validated['end_time'] = $endTime->format('H:i');
|
||||
}
|
||||
}
|
||||
|
||||
// --- Store reservation ---
|
||||
$data = $this->reservationRepository->store($validated);
|
||||
|
||||
return $this->responseSuccess($data, 'Reservation created successfully.');
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function banners(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = Banner::where('restaurant_id', $restaurantId)
|
||||
->where('status', 1)
|
||||
->get();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'Banners has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function aboutUs(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = AboutUs::where('restaurant_id', $restaurantId)
|
||||
->where('status', 1)
|
||||
->first();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'AboutUs has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function academicImages(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data['pageTitle'] = 'Academic Images';
|
||||
$data['academicImages'] = AcademicImage::where('restaurant_id', $restaurantId)->get();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'AcademicImages has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function whyChooseUs(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = WhyChooseUs::select(
|
||||
'id',
|
||||
'restaurant_id',
|
||||
'title',
|
||||
'description',
|
||||
'icon',
|
||||
'created_at',
|
||||
)
|
||||
->where('restaurant_id', $restaurantId)
|
||||
->get();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'WhyChooseUs has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function readyToJoinUs(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = ReadyToJoinUs::select(
|
||||
'id',
|
||||
'restaurant_id',
|
||||
'title',
|
||||
'description',
|
||||
'icon',
|
||||
'button_name',
|
||||
'button_link',
|
||||
'created_at',
|
||||
)
|
||||
->where('restaurant_id', $restaurantId)
|
||||
->where('status', 1)
|
||||
->get();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'ReadyToJoinUs has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function faq(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = FaqQuestion::where('restaurant_id', $restaurantId)
|
||||
->where('status', 1)
|
||||
->select('id', 'restaurant_id', 'question', 'answer')
|
||||
->get();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'Faqs has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function privacyPolicy(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = Policy::where('restaurant_id', $restaurantId)->select('id', 'restaurant_id', 'type', 'description')->whereType(1)->first();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'Privacy Policy has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function cookiePolicy(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = Policy::where('restaurant_id', $restaurantId)
|
||||
->where('status', 1)
|
||||
->select('id', 'restaurant_id', 'type', 'description')->whereType(2)->first();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'Cookie Policy has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function termConditions(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = Policy::where('restaurant_id', $restaurantId)
|
||||
->where('status', 1)
|
||||
->select('id', 'restaurant_id', 'type', 'description')->whereType(3)->first();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'Terms & Conditions has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function ourHistory(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = OurHistory::where('restaurant_id', $restaurantId)
|
||||
->select(
|
||||
'restaurant_id',
|
||||
'year',
|
||||
'title',
|
||||
'descriptions',
|
||||
'status',
|
||||
'created_by',
|
||||
)->first();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'Our History has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testimonials(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = Testimonial::select(
|
||||
'restaurant_id',
|
||||
'name',
|
||||
'description',
|
||||
'thumbnail_image',
|
||||
'video_url',
|
||||
'note',
|
||||
'ratting',
|
||||
'status',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
)
|
||||
->where('restaurant_id', $restaurantId)
|
||||
->where('status', 1)
|
||||
->get();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'Testimonials has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function mobileAppSections(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = MobileAppSection::select(
|
||||
'id',
|
||||
'restaurant_id',
|
||||
'title',
|
||||
'heading',
|
||||
'description',
|
||||
'image',
|
||||
'feature_one',
|
||||
'feature_two',
|
||||
'feature_three',
|
||||
'play_store_link',
|
||||
'app_store_link',
|
||||
)
|
||||
->where('restaurant_id', $restaurantId)
|
||||
->where('status', 1)
|
||||
->get();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'MobileAppSections has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function settings(Request $request): JsonResponse
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$allowedKeys = [
|
||||
'restaurant_name',
|
||||
'site_title',
|
||||
'phone',
|
||||
'email',
|
||||
'language',
|
||||
'google_map',
|
||||
'address',
|
||||
'timezone',
|
||||
'academic_year',
|
||||
'currency_symbol',
|
||||
'logo',
|
||||
'copyright_text',
|
||||
'facebook_link',
|
||||
'google_plus_link',
|
||||
'youtube_link',
|
||||
'whats_app_link',
|
||||
'twitter_link',
|
||||
'eiin_code',
|
||||
'header_notice',
|
||||
'exam_result_status',
|
||||
'admission_display_status',
|
||||
'guidance',
|
||||
'academic_office',
|
||||
'website_link',
|
||||
'primary_color',
|
||||
'secondary_color',
|
||||
'primary_container_color',
|
||||
'dark_primary_color',
|
||||
'dark_secondary_color',
|
||||
'dark_container_color',
|
||||
'text_color',
|
||||
'dark_text_color',
|
||||
'sidebar_selected_bg_color',
|
||||
'sidebar_selected_text_color',
|
||||
];
|
||||
|
||||
$settings = DB::table('settings')
|
||||
->whereIn('option_key', $allowedKeys)
|
||||
->where('restaurant_id', $restaurantId)
|
||||
->pluck('option_value', 'option_key');
|
||||
|
||||
return $this->responseSuccess(
|
||||
$settings,
|
||||
'Settings have been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function contactUs(ContactStoreRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
// Create or get existing contact for this restaurant & email
|
||||
$contact = Contact::firstOrCreate(
|
||||
[
|
||||
'restaurant_id' => $restaurantId,
|
||||
'email' => $request->email,
|
||||
],
|
||||
[
|
||||
'phone' => $request->phone ?? null,
|
||||
'message' => $request->message ?? null,
|
||||
]
|
||||
);
|
||||
|
||||
return $this->responseSuccess(
|
||||
[
|
||||
'id' => $contact->id,
|
||||
'email' => $contact->email,
|
||||
],
|
||||
'Contact form submitted successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function themes(Request $request)
|
||||
{
|
||||
$themes = Theme::where('status', 1)->get();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$themes,
|
||||
'Themes get successfully.'
|
||||
);
|
||||
}
|
||||
|
||||
public function defaultTheme(Request $request)
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
$themeId = Restaurant::where('id', $restaurantId)
|
||||
->value('theme_id'); // or default_theme_id if you use that
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'default_theme_id' => $themeId,
|
||||
]);
|
||||
}
|
||||
|
||||
public function onboarding(OnboardingStoreRequest $request): JsonResponse
|
||||
{
|
||||
// Step 2: Handle other validation logic and file uploads
|
||||
$validated = $request->validated();
|
||||
|
||||
// Handle the restaurant_logo file upload if it exists
|
||||
$restaurantLogoPath = null;
|
||||
if ($request->hasFile('restaurant_logo')) {
|
||||
$restaurantLogoPath = fileUploader('restaurants/', 'png', $request->file('restaurant_logo'));
|
||||
}
|
||||
|
||||
// Handle the user_avatar file upload if it exists
|
||||
$userAvatarPath = null;
|
||||
if ($request->hasFile('user_avatar')) {
|
||||
$userAvatarPath = fileUploader('user_avatars/', 'png', $request->file('user_avatar'));
|
||||
}
|
||||
|
||||
// Step 3: Save onboarding data
|
||||
$onboarding = Onboarding::create([
|
||||
'restaurant_name' => $validated['restaurant_name'],
|
||||
'restaurant_email' => $validated['restaurant_email'],
|
||||
'restaurant_phone' => $validated['restaurant_phone'],
|
||||
'restaurant_domain' => $validated['restaurant_domain'],
|
||||
'restaurant_type' => $validated['restaurant_type'],
|
||||
'restaurant_address' => $validated['restaurant_address'],
|
||||
'name' => $validated['name'],
|
||||
'email' => $validated['email'],
|
||||
'phone' => $validated['phone'],
|
||||
'password' => Hash::make($validated['password']),
|
||||
'restaurant_logo' => $restaurantLogoPath,
|
||||
'user_avatar' => $userAvatarPath,
|
||||
'status' => 'in_progress',
|
||||
]);
|
||||
|
||||
// Create the new restaurant
|
||||
$restaurant = Restaurant::create([
|
||||
'name' => $onboarding->restaurant_name,
|
||||
'restaurant_type' => $onboarding->restaurant_type,
|
||||
'email' => $onboarding->restaurant_email,
|
||||
'phone' => $onboarding->restaurant_phone,
|
||||
'domain' => $onboarding->restaurant_domain,
|
||||
'address' => $onboarding->restaurant_address,
|
||||
'logo' => $onboarding->restaurant_logo,
|
||||
]);
|
||||
|
||||
$user = RestaurantSetupService::setup($restaurant, [
|
||||
'name' => $onboarding->name,
|
||||
'email' => $onboarding->email,
|
||||
'phone' => $onboarding->phone,
|
||||
'password' => $onboarding->password,
|
||||
'avatar' => $onboarding->avatar,
|
||||
]);
|
||||
|
||||
$accessToken = $user->createToken('app')->accessToken;
|
||||
|
||||
// Return success response
|
||||
return $this->responseSuccess(
|
||||
[
|
||||
'user' => $user,
|
||||
'access_token' => $accessToken,
|
||||
],
|
||||
'Onboarding request submitted successfully.'
|
||||
);
|
||||
}
|
||||
|
||||
public function restaurantSchedules(Request $request)
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$perPage = $request->input('perPage', 15);
|
||||
$sortBy = $request->input('sortBy', 'id');
|
||||
$sortDir = $request->input('sortDir', 'desc');
|
||||
$search = $request->input('search');
|
||||
|
||||
$query = RestaurantSchedule::query()
|
||||
->with('times:id,restaurant_schedule_id,open_time,close_time')
|
||||
->where('restaurant_id', $restaurantId);
|
||||
|
||||
// 🔍 Search Filter
|
||||
if (! empty($search)) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('day', 'LIKE', "%{$search}%")
|
||||
->orWhere('start_date', 'LIKE', "%{$search}%")
|
||||
->orWhere('end_date', 'LIKE', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
// 🔽 Sorting
|
||||
$query->orderBy($sortBy, $sortDir);
|
||||
|
||||
// 📄 Pagination
|
||||
$data = $query->get();
|
||||
|
||||
return $this->responseSuccess($data, 'Restaurant schedule fetched successfully.');
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function reservationUnavailability(Request $request)
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = ReservationUnavailable::select(
|
||||
'id',
|
||||
'restaurant_id',
|
||||
'table_id',
|
||||
'date',
|
||||
'start_time',
|
||||
'end_time',
|
||||
'reason'
|
||||
)
|
||||
->with('table')
|
||||
->where('restaurant_id', $restaurantId)
|
||||
->get();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'Restaurant Unavailability has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function reservationSettings(Request $request)
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = ReservationSetting::where('restaurant_id', $restaurantId)->get();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'Reservation Settings has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function cmsSections(Request $request)
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = CMSSection::where('restaurant_id', $restaurantId)
|
||||
->orderBy('serial', 'asc')
|
||||
->get();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'Restaurant CMS Sections has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function restaurantImageSAASSetting(Request $request)
|
||||
{
|
||||
try {
|
||||
$data = RestaurantImageSAASSetting::first();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'Restaurant SAAS Settings Image has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function restaurantImageSetting(Request $request)
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = RestaurantImageSetting::where('restaurant_id', $restaurantId)->first();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'Restaurant Settings Image has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function getCoupons(Request $request)
|
||||
{
|
||||
$restaurantId = $this->getRestaurantIdFromHeader($request);
|
||||
if ($restaurantId instanceof JsonResponse) {
|
||||
return $restaurantId;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = Coupon::where('restaurant_id', $restaurantId)->first();
|
||||
|
||||
return $this->responseSuccess(
|
||||
$data,
|
||||
'Coupons has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function getRestaurantIdFromHeader(Request $request): mixed
|
||||
{
|
||||
$domain = $request->header('X-Domain'); // Custom header key (Change if needed)
|
||||
if (! $domain) {
|
||||
return $this->responseError([], 'Domain header is missing.', 400);
|
||||
}
|
||||
|
||||
$restaurantResponse = RestaurantHelper::getRestaurantIdByDomain($domain);
|
||||
if (! $restaurantResponse['status']) {
|
||||
return $this->responseError([], $restaurantResponse['error'], 404);
|
||||
}
|
||||
|
||||
return $restaurantResponse['restaurant_id'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Frontend\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\RequestSanitizerTrait;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\Frontend\Http\Requests\MobileAppSection\MobileAppSectionStoreRequest;
|
||||
use Modules\Frontend\Http\Requests\MobileAppSection\MobileAppSectionUpdateRequest;
|
||||
use Modules\Frontend\Repositories\MobileAppSectionRepository;
|
||||
|
||||
class MobileAppSectionController extends Controller
|
||||
{
|
||||
use RequestSanitizerTrait;
|
||||
|
||||
public function __construct(private MobileAppSectionRepository $faq) {}
|
||||
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->getAll(request()->all()),
|
||||
'MobileAppSection has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function store(MobileAppSectionStoreRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->create($request->all()),
|
||||
'MobileAppSection has been created successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->getById($id),
|
||||
'MobileAppSection has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function update(MobileAppSectionUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->update($id, $this->getUpdateRequest($request)),
|
||||
'MobileAppSection has been updated successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->delete($id),
|
||||
'MobileAppSection has been deleted successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Frontend\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\RequestSanitizerTrait;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\Frontend\Http\Requests\Policy\PolicyStoreRequest;
|
||||
use Modules\Frontend\Http\Requests\Policy\PolicyUpdateRequest;
|
||||
use Modules\Frontend\Repositories\PolicyRepository;
|
||||
|
||||
class PolicyController extends Controller
|
||||
{
|
||||
use RequestSanitizerTrait;
|
||||
|
||||
public function __construct(private PolicyRepository $policy) {}
|
||||
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->policy->getAll(request()->all()),
|
||||
'Policy has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function store(PolicyStoreRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->policy->create($request->all()),
|
||||
'Policy has been created successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->policy->getById($id),
|
||||
'Policy has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function update(PolicyUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->policy->update($id, $this->getUpdateRequest($request)),
|
||||
'Policy has been updated successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->policy->delete($id),
|
||||
'Policy has been deleted successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Frontend\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\RequestSanitizerTrait;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\Frontend\Http\Requests\ReadyToJoinUs\ReadyToJoinUsStoreRequest;
|
||||
use Modules\Frontend\Http\Requests\ReadyToJoinUs\ReadyToJoinUsUpdateRequest;
|
||||
use Modules\Frontend\Repositories\ReadyToJoinUsRepository;
|
||||
|
||||
class ReadyToJoinUsController extends Controller
|
||||
{
|
||||
use RequestSanitizerTrait;
|
||||
|
||||
public function __construct(private ReadyToJoinUsRepository $faq) {}
|
||||
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->getAll(request()->all()),
|
||||
'ReadyToJoinUs has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function store(ReadyToJoinUsStoreRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->create($request->all()),
|
||||
'ReadyToJoinUs has been created successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->getById($id),
|
||||
'ReadyToJoinUs has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function update(ReadyToJoinUsUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->update($id, $this->getUpdateRequest($request)),
|
||||
'ReadyToJoinUs has been updated successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->delete($id),
|
||||
'ReadyToJoinUs has been deleted successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Frontend\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\RequestSanitizerTrait;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\Frontend\Http\Requests\Testimonial\TestimonialStoreRequest;
|
||||
use Modules\Frontend\Http\Requests\Testimonial\TestimonialUpdateRequest;
|
||||
use Modules\Frontend\Repositories\TestimonialRepository;
|
||||
|
||||
class TestimonialsController extends Controller
|
||||
{
|
||||
use RequestSanitizerTrait;
|
||||
|
||||
public function __construct(private TestimonialRepository $testimonial) {}
|
||||
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->testimonial->getAll(request()->all()),
|
||||
'Testimonial has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function store(TestimonialStoreRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->testimonial->create($request->all()),
|
||||
'Testimonial has been created successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->testimonial->getById($id),
|
||||
'Testimonial has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function update(TestimonialUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->testimonial->update($id, $this->getUpdateRequest($request)),
|
||||
'Testimonial has been updated successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->testimonial->delete($id),
|
||||
'Testimonial has been deleted successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Frontend\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\RequestSanitizerTrait;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\Frontend\Http\Requests\WhyChooseUs\WhyChooseUsStoreRequest;
|
||||
use Modules\Frontend\Http\Requests\WhyChooseUs\WhyChooseUsUpdateRequest;
|
||||
use Modules\Frontend\Repositories\WhyChooseUsRepository;
|
||||
|
||||
class WhyChooseUsController extends Controller
|
||||
{
|
||||
use RequestSanitizerTrait;
|
||||
|
||||
public function __construct(private WhyChooseUsRepository $faq) {}
|
||||
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->getAll(request()->all()),
|
||||
'WhyChooseUs has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return $this->responseError([], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function store(WhyChooseUsStoreRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->create($request->all()),
|
||||
'WhyChooseUs has been created successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->getById($id),
|
||||
'WhyChooseUs has been fetched successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function update(WhyChooseUsUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->update($id, $this->getUpdateRequest($request)),
|
||||
'WhyChooseUs has been updated successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return $this->responseSuccess(
|
||||
$this->faq->delete($id),
|
||||
'WhyChooseUs has been deleted successfully.'
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
return $this->responseError([], $exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user