From 25b5576f5741eda8a24272ad70520fbd4528fb2e Mon Sep 17 00:00:00 2001 From: Max Matiukhin Date: Thu, 8 Jun 2017 11:19:38 +0100 Subject: [PATCH] generate methods for the SoftDeletes trait (#518) --- src/Console/ModelsCommand.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index abcdbf2..12836b8 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -206,6 +206,7 @@ class ModelsCommand extends Command } $this->getPropertiesFromMethods($model); + $this->getSoftDeleteMethods($model); $output .= $this->createPhpDocs($name); $ignore[] = $name; $this->nullableColumns = []; @@ -746,4 +747,21 @@ class ModelsCommand extends Command return $type; } + + /** + * Generates methods provided by the SoftDeletes trait + * @param \Illuminate\Database\Eloquent\Model $model + */ + protected function getSoftDeleteMethods($model) + { + $traits = class_uses(get_class($model), true); + if (in_array('Illuminate\\Database\\Eloquent\\SoftDeletes', $traits)) { + $this->setMethod('forceDelete', 'bool|null', []); + $this->setMethod('restore', 'bool|null', []); + + $this->setMethod('withTrashed', '\Illuminate\Database\Query\Builder|\\' . get_class($model), []); + $this->setMethod('withoutTrashed', '\Illuminate\Database\Query\Builder|\\' . get_class($model), []); + $this->setMethod('onlyTrashed', '\Illuminate\Database\Query\Builder|\\' . get_class($model), []); + } + } }