mein-sterntours/app/Repositories/BookingRepository.php
2020-05-28 19:03:42 +02:00

73 lines
No EOL
2.1 KiB
PHP

<?php
namespace App\Repositories;
use App\Models\Booking;
use App\Models\BookingCountryService;
class BookingRepository extends BaseRepository {
public function __construct(Booking $model)
{
$this->model = $model;
}
public function update($data)
{
return $this->model;
}
public function updateBooking($id, $data){
$this->model = Booking::findOrFail($id);
$fill = [
'paying_out' => $data['paying_out'],
'paying_out_status' => $data['paying_out_status'],
'airline_id' => $data['airline_id'],
'refund' => $data['refund'],
'refund_date' => _reformat_date($data['refund_date']),
'lawyer_date' => _reformat_date($data['lawyer_date']),
'hold' => $data['hold'],
'xx_tkt' => $data['xx_tkt'],
'xx_tkt_date' => _reformat_date($data['xx_tkt_date']),
'filekey' => $data['filekey'],
'is_rail_fly' => isset($data['is_rail_fly']) ? true : false,
'notice' => $data['notice'],
];
$this->model->fill($fill);
$this->model->save();
if(isset($data['country_service'])){
$this->updateCountryService($data['country_service']);
}
return $this->model;
}
public function updateCountryService($country_services){
foreach ($country_services as $country_service_id=>$val){
$booking_country_service = BookingCountryService::where('travel_country_service_id', '=', $country_service_id)
->where('booking_id', '=', $this->model->id)->first();
if(!$booking_country_service){
$booking_country_service = BookingCountryService::create([
'travel_country_service_id' => $country_service_id,
'booking_id' => $this->model->id,
'status' => $val
]);
}else{
$booking_country_service->fill([
'status' => $val
]);
$booking_country_service->save();
}
}
}
}