I am using Laravel (5.8) and I need to delete a record from table A and then also table B. So I tried Observers, but it never fired the observer's deleted
method.
I already used other methods like updating
or updated
, so I don't know why the deleted
method is not firing.
I don't use soft delete, because I didn't make this database schema and I don't have authorities to modify that. But based on what I read from the document, it doesn't matter..right?
Here are my code.
- Pay Controller.php
public function delete(Request $request, $idx){
$payData = PaymentData::where('idx', $idx)->delete();
return response()->json(['status' => true]);
}
- PayObserver.php
public function deleted(PaymentData $paymentData)
{
if ($paymentData->pay_type == "PA") {
$app = AppData::where('oid', $paymentData->oid)->first();
if (!empty($app)) {
$app->delete();
}
}
}
- AppServiceProvider.php
public function boot()
{
\App\Models\PaymentData::observe(\App\Observers\PayObserver::class);
}
I also tried to add the observe statement to boot method in EventServiceProvider.php
, but it wasn't working either.
I read the official document but couldn't find any clues..what did I miss?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/wCrJgFb
via IFTTT
Aucun commentaire:
Enregistrer un commentaire