Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Laravel中扩展集合_Php_Laravel_Laravel 4 - Fatal编程技术网

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;
    }
}

我正要删除,但这可能会对将来的人有所帮助。结果我只需要刷新我的模型缓存