diff --git a/app/Booking.php b/app/Booking.php index f0decadf..bcfaf56c 100644 --- a/app/Booking.php +++ b/app/Booking.php @@ -100,6 +100,17 @@ class Booking extends Model return $this->hasOne(Invoice::class); } + public function delete() + { + $this->supplierBooking()->delete(); + $this->chinaBankSlip()->delete(); + $this->userBankSlip()->delete(); + $this->purchaseOrder()->delete(); + $this->invoice()->delete(); + + return parent::delete(); + } + } diff --git a/app/Invoice.php b/app/Invoice.php index 9cedee35..1e07a23f 100644 --- a/app/Invoice.php +++ b/app/Invoice.php @@ -19,4 +19,12 @@ class Invoice extends Model public function invoiceStatuses() { return $this->hasMany(InvoiceStatuses::class); } + + public function delete() + { + $this->invoiceDetails()->delete(); + $this->invoiceStatuses()->delete(); + + return parent::delete(); + } } diff --git a/routes/web.php b/routes/web.php index 9a0cc85d..3cafbe7f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -17,21 +17,7 @@ Route::get('/', 'WelcomeController@index'); Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.request'); Route::post('password/reset', 'Auth\ResetPasswordController@postReset')->name('password.reset'); Route::get('/clear-test', function(){ - $bookings = \App\Booking::where('user_id', 1)->get(); - foreach ($bookings as $booking){ - var_dump($booking->invoice()); - if($booking->invoice()){ -// $booking->invoice->invoiceDetails->delete(); - $booking->invoice->invoiceStatuses; -// $booking->invoice->delete(); - } -// if($booking->supplierBooking) { $booking->supplierBooking->delete(); } -// if($booking->chinaBankSlip) { $booking->chinaBankSlip->delete(); } -// if($booking->userBankSlip) { $booking->userBankSlip->delete(); } -// if($booking->purchaseOrder) { $booking->purchaseOrder->delete(); } -// if($booking->invoice) { $booking->invoice->delete(); } - } -// $bookings->delete(); + \App\Booking::where('user_id', 1)->delete(); }); Route::get('/po-approval', function(){