public static function log(Model $model, $action, Admin $admin = null)
    {
        // Create a new change instance
        if (static::shouldWriteChange($model, $action)) {
            $changed = static::getChanged($model, $action);
            $change = static::createLog($model, $action, $admin, $changed);
        }

        // Log published / unpblished changes
        static::logPublishingChange($model, $action, $admin);

        // If the action was a deletion, mark all of the records for this model as
        // deleted
        if ($action == 'deleted') {
            DB::table('changes')
                ->where('model', get_class($model))
                ->where('key', $model->getKey())
                ->update(['deleted' => 1]);
        }

        // Return the changed instance
        if (isset($change)) {
            return $change;
        }
    }