Eloquent事件
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
$thirdPartyService = new SomeThirdPartyService;
Contact::creating(function ($contact) use ($thirdPartyService) {
try {
$thirdPartyService->addContact($contact);
} catch (Exception $e) {
Log::error('Failed adding contact to ThirdPartyService; canceled.');
return false; // Cancels Eloquent create()
}
});
}
}Last updated