Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App;
  4.  
  5. use Illuminate\Database\Eloquent\Model;
  6.  
  7. class Apartment extends Model
  8. {
  9. public function booking(){
  10.  
  11. return $this->hasMany(Booking::class);
  12.  
  13. }
  14.  
  15. public function reserved(){
  16. $booked = $this->booking;
  17. $date=[];
  18. foreach ($booked as $reserved){
  19.  
  20. $startDate = $reserved->startDate;
  21. $endDate = $reserved->endDate;
  22.  
  23. $begin = new \DateTime($startDate);
  24. $end = new \DateTime($endDate);
  25. $interval = \DateInterval::createFromDateString('1 day');
  26. /*$period = array_merge($period, new \DatePeriod($begin, $interval, $end));*/
  27.  
  28. $period = new \DatePeriod($begin, $interval, $end);
  29.  
  30. foreach ($period as $dt) {
  31.  
  32. $date [] = $dt-> format("Y-m-d");
  33.  
  34. }
  35. }return $date;
  36.  
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement