Php 在Laravel中扩展集合
我正试图在拉威尔扩展我的模型收藏。我在这里学习这两个教程,它们说我只需要重写Php 在Laravel中扩展集合,php,laravel,laravel-4,Php,Laravel,Laravel 4,我正试图在拉威尔扩展我的模型收藏。我在这里学习这两个教程,它们说我只需要重写newCollection方法。看起来很简单,但是newCollection方法似乎没有启动 我用的是Laravel4.2 我的模型: class City extends Eloquent { public function newCollection(array $models = Array()) { echo 'here'; return new Extens
newCollection
方法。看起来很简单,但是newCollection
方法似乎没有启动
我用的是Laravel4.2
我的模型:
class City extends Eloquent {
public function newCollection(array $models = Array())
{
echo 'here';
return new Extensions\CityCollection($models);
}
}
自定义集合:
<?php namespace Extensions;
echo 'here';
class CityCollection extends \Illuminate\Database\Eloquent\Collection {
public function findInList($name)
{
foreach ($this as $city)
{
if (strtolower($city->name) === strtolower($name))
{
return $city;
}
}
return false;
}
}
我正要删除,但这可能会对将来的人有所帮助。结果我只需要刷新我的模型缓存