From b582f5d1a0728a7c7105d950dd5f4d33e17ddaaa Mon Sep 17 00:00:00 2001 From: omair saleh Date: Tue, 29 Sep 2020 14:21:22 +0800 Subject: [PATCH] clear test user data --- app/Booking.php | 11 +++++++++++ app/Invoice.php | 8 ++++++++ routes/web.php | 16 +--------------- 3 files changed, 20 insertions(+), 15 deletions(-) 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(){