Created
August 15, 2014 09:37
-
-
Save dennisoderwald/a100edcb0fab6981a230 to your computer and use it in GitHub Desktop.
morphMany Issue (Now I receive a JSON output with the filtered object, when I call: $model->metas->meta_key)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Meta extends Eloquent { | |
public function newCollection(array $models = array()) | |
{ | |
return new MetaCollection($models); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Eloquent\Collection; | |
class MetaCollection extends Collection { | |
public function __get($name) | |
{ | |
$this->temp = $name; | |
return $this->filter(function (Meta $item) { | |
return $item->key == $this->temp; | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Resort extends Eloquent { | |
public function metas() | |
{ | |
return $this->morphMany('Meta', 'metable'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment