Server IP : 66.29.132.124 / Your IP : 3.14.254.103 Web Server : LiteSpeed System : Linux business141.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : wavevlvu ( 1524) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/wavevlvu/book24.ng/modules/Api/Controllers/ |
Upload File : |
<?php namespace Modules\Api\Controllers; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Modules\Booking\Models\Service; use Modules\Flight\Controllers\FlightController; class SearchController extends Controller { public function search($type = ''){ $type = $type ? $type : request()->get('type'); if(empty($type)) { return $this->sendError(__("Type is required")); } $class = get_bookable_service_by_id($type); if(empty($class) or !class_exists($class)){ return $this->sendError(__("Type does not exists")); } $rows = call_user_func([$class,'search'],request()); $total = $rows->total(); return $this->sendSuccess( [ 'total'=>$total, 'total_pages'=>$rows->lastPage(), 'data'=>$rows->map(function($row){ return $row->dataForApi(); }), ] ); } public function searchServices(){ $rows = call_user_func([new Service(),'search'],request()); $total = $rows->total(); return $this->sendSuccess( [ 'total'=>$total, 'total_pages'=>$rows->lastPage(), 'data'=>$rows->map(function($row){ return $row->dataForApi(); }), ] ); } public function getFilters($type = ''){ $type = $type ? $type : request()->get('type'); if(empty($type)) { return $this->sendError(__("Type is required")); } $class = get_bookable_service_by_id($type); if(empty($class) or !class_exists($class)){ return $this->sendError(__("Type does not exists")); } $data = call_user_func([$class,'getFiltersSearch'],request()); return $this->sendSuccess( [ 'data'=>$data ] ); } public function getFormSearch($type = ''){ $type = $type ? $type : request()->get('type'); if(empty($type)) { return $this->sendError(__("Type is required")); } $class = get_bookable_service_by_id($type); if(empty($class) or !class_exists($class)){ return $this->sendError(__("Type does not exists")); } $data = call_user_func([$class,'getFormSearch'],request()); return $this->sendSuccess( [ 'data'=>$data ] ); } public function detail($type = '',$id = '') { if(empty($type)){ return $this->sendError(__("Resource is not available")); } if(empty($id)){ return $this->sendError(__("Resource ID is not available")); } $class = get_bookable_service_by_id($type); if(empty($class) or !class_exists($class)){ return $this->sendError(__("Type does not exists")); } $row = $class::find($id); if(empty($row)) { return $this->sendError(__("Resource not found")); } if($type=='flight'){ return (new FlightController())->getData(\request(),$id); } return $this->sendSuccess([ 'data'=>$row->dataForApi(true) ]); } public function checkAvailability(Request $request , $type = '',$id = ''){ if(empty($type)){ return $this->sendError(__("Resource is not available")); } if(empty($id)){ return $this->sendError(__("Resource ID is not available")); } $class = get_bookable_service_by_id($type); if(empty($class) or !class_exists($class)){ return $this->sendError(__("Type does not exists")); } $classAvailability = $class::getClassAvailability(); $classAvailability = new $classAvailability(); $request->merge(['id' => $id]); if($type == "hotel"){ $request->merge(['hotel_id' => $id]); return $classAvailability->checkAvailability($request); } return $classAvailability->loadDates($request); } public function checkBoatAvailability(Request $request ,$id = ''){ if(empty($id)){ return $this->sendError(__("Boat ID is not available")); } $class = get_bookable_service_by_id('boat'); $classAvailability = $class::getClassAvailability(); $classAvailability = new $classAvailability(); $request->merge(['id' => $id]); return $classAvailability->availabilityBooking($request); } }