/** * Either purge all the records at once or loop through them one by one. * * This is to allow events to get fired for each record if needed. * * @param Builder $query * @param string $model_name * * @return int */ protected function purgeRecordsAsConfigured(Builder $query, $model_name) { if ($this->fire_purge_events !== true) { $this->recordMessage("Deleting all the records in a single query statement."); return $query->forceDelete(); } $this->recordMessage("Deleting each record separately and firing events."); $records = $query->get(); foreach ($records as $record) { $this->firePurgeEvent('purging', $model_name, $record); $record->forceDelete(); $this->firePurgeEvent('purged', $model_name, $record); } return $records->count(); }
/** * Run the default delete function on the builder. * * @return mixed * @static */ public static function forceDelete() { return \Illuminate\Database\Eloquent\Builder::forceDelete(); }