generate methods for the SoftDeletes trait (#518)

This commit is contained in:
Max Matiukhin
2017-06-08 12:19:38 +02:00
committed by Barry vd. Heuvel
parent d6d99994c3
commit 25b5576f57
+18
View File
@@ -206,6 +206,7 @@ class ModelsCommand extends Command
} }
$this->getPropertiesFromMethods($model); $this->getPropertiesFromMethods($model);
$this->getSoftDeleteMethods($model);
$output .= $this->createPhpDocs($name); $output .= $this->createPhpDocs($name);
$ignore[] = $name; $ignore[] = $name;
$this->nullableColumns = []; $this->nullableColumns = [];
@@ -746,4 +747,21 @@ class ModelsCommand extends Command
return $type; 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), []);
}
}
} }