mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 18:13:11 +00:00
Merge pull request #77 from ukautz/feature-polymorphic
Added property methods for polymorphic relations
This commit is contained in:
@@ -287,14 +287,14 @@ class ModelsCommand extends Command {
|
|||||||
$begin = strpos($code, 'function(');
|
$begin = strpos($code, 'function(');
|
||||||
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
|
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
|
||||||
|
|
||||||
foreach(array('hasMany', 'belongsToMany', 'hasOne', 'belongsTo') as $relation){
|
foreach(array('hasMany', 'belongsToMany', 'hasOne', 'belongsTo', 'morphTo', 'morphMany', 'morphToMany') as $relation){
|
||||||
$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, stripos($code, ')')));
|
||||||
//Remove quotes, ensure 1 \ in front of the model
|
//Remove quotes, ensure 1 \ in front of the model
|
||||||
$returnModel = "\\".ltrim(trim($arguments[0], " \"'"), "\\");
|
$returnModel = "\\".ltrim(trim($arguments[0], " \"'"), "\\");
|
||||||
if($relation === "belongsToMany" or $relation === 'hasMany'){
|
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($method, '\Illuminate\Database\Eloquent\Collection|'.$returnModel.'[]', true, null);
|
$this->setProperty($method, '\Illuminate\Database\Eloquent\Collection|'.$returnModel.'[]', true, null);
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
Reference in New Issue
Block a user