mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-19 10:33:11 +00:00
Fixed class name resolution via get_class() and static::class.
This commit is contained in:
@@ -331,9 +331,9 @@ class ModelsCommand extends Command
|
|||||||
$search = '$this->' . $relation . '(';
|
$search = '$this->' . $relation . '(';
|
||||||
if ($pos = stripos($code, $search)) {
|
if ($pos = stripos($code, $search)) {
|
||||||
$code = substr($code, $pos + strlen($search));
|
$code = substr($code, $pos + strlen($search));
|
||||||
$arguments = explode(',', substr($code, 0, stripos($code, ')')));
|
$arguments = explode(',', substr($code, 0, strpos($code, ');')));
|
||||||
//Remove quotes, ensure 1 \ in front of the model
|
//Remove quotes, ensure 1 \ in front of the model
|
||||||
$returnModel = $this->getClassName($arguments[0]);
|
$returnModel = $this->getClassName($arguments[0], $model);
|
||||||
if ($relation === "belongsToMany" or $relation === 'hasMany' or $relation === 'morphMany' or $relation === 'morphToMany') {
|
if ($relation === "belongsToMany" or $relation === 'hasMany' or $relation === 'morphMany' or $relation === 'morphToMany') {
|
||||||
//Collection or array of models (because Collection is Arrayable)
|
//Collection or array of models (because Collection is Arrayable)
|
||||||
$this->setProperty(
|
$this->setProperty(
|
||||||
@@ -507,9 +507,19 @@ class ModelsCommand extends Command
|
|||||||
return $paramsWithDefault;
|
return $paramsWithDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getClassName($className)
|
/**
|
||||||
|
* @param string $className
|
||||||
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getClassName($className, $model)
|
||||||
{
|
{
|
||||||
// If the class name was resovled via ::class (PHP 5.5+)
|
// If the class name was resolved via get_class($this) or static::class
|
||||||
|
if(strpos($className, 'get_class($this)') !== false || strpos($className, 'static::class') !== false) {
|
||||||
|
return get_class($model);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the class name was resolved via ::class (PHP 5.5+)
|
||||||
if(strpos($className, '::class') !== false) {
|
if(strpos($className, '::class') !== false) {
|
||||||
$end = -1 * strlen('::class');
|
$end = -1 * strlen('::class');
|
||||||
return substr($className, 0, $end);
|
return substr($className, 0, $end);
|
||||||
|
|||||||
Reference in New Issue
Block a user