mein-sterntours/app/Repositories/CustomerRepository.php
Kevin Adametz 881fc84207 08 2024
2024-08-05 11:58:09 +02:00

44 lines
No EOL
1,014 B
PHP

<?php
namespace App\Repositories;
use App\Models\Lead;
use App\Models\Booking;
use App\Models\Customer;
class CustomerRepository extends BaseRepository {
public function __construct(Customer $model)
{
$this->model = $model;
}
public function updateCustomer($id, $data)
{
$this->model = Customer::findOrFail($id);
$this->model->fill($data);
$this->model->save();
return $this->model;
}
//by Lead ID
public function updateCustomerFromLead($id, $data){
$lead = Lead::findOrFail($id);
if(isset($data['customer']) && $lead->customer){
return $this->updateCustomer($lead->customer->id, $data['customer']);
}
}
//by Booking ID
public function updateCustomerFromBooking($id, $data){
$booking = Booking::findOrFail($id);
if(isset($data['customer']) && $booking->customer){
return $this->updateCustomer($booking->customer->id, $data['customer']);
}
}
}