Guest User

Untitled

a guest
Jun 24th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. public static function filterTourismPackage($params=''){
  2. //inner join all
  3. $collect = DB::table('tourism_package')->join('tenant_tourism_package', function( $join ) use ( $params ){
  4. $filter = $join->on('tourism_package.id','=','tenant_tourism_package.tourism_package_id');
  5. if( !empty($params['package']) ){
  6. $filter->whereIn('tenant_tourism_package.tourism_package_id',$params['package']);
  7. }
  8. })
  9. ->join('tourism_belt', function( $join ) use ( $params ) {
  10. $filter = $join->on('tourism_package.tourism_belt_id','=','tourism_belt.id');
  11. if( !empty($params['belt']) ){
  12. $filter->whereIn('tourism_belt.id',$params['belt']);
  13. }
  14. })
  15. //redudant
  16. ->join('ekraf_tenants as tenants', function( $join ){
  17. $join->on('tenant_tourism_package.ekraf_tenant_id','=','tenants.id');
  18. })
  19. ->join('tenant_categories', function( $join ){
  20. $filter = $join->on('tenants.id','=','tenant_categories.ekraf_tenant_id');
  21. if( !empty( $params['subsector'] ) ){
  22. $filter->whereIn('tenant_categories.category_id',$params['subsector']);
  23. }
  24. })
  25. ->join('tenant_address', function( $join ) {
  26. $join->on('tenants.id','=','tenant_address.ekraf_tenant_id');
  27. })
  28. ->select('tenants.id','tourism_package.id as id_package','tenant_address.latitude','tenant_address.longitude')
  29. ->distinct('tenants.id');
  30. if( !empty( $params['keyword'] ) ){
  31. $collect = $collect->where('tenants.tenant_name','like','%'. $params['keyword'] .'%');
  32. }
  33.  
  34. return $collect->get();
  35. }
Add Comment
Please, Sign In to add comment