How to manually create a new empty Eloquent Collection in Laravel 4

前端 未结 7 1807
礼貌的吻别
礼貌的吻别 2020-12-14 14:21

How do we create a new Eloquent Collection in Laravel 4, without using Query Builder?

There is a newCollection() method which can be overridden by that

7条回答
  •  时光说笑
    2020-12-14 14:40

    It is better to use the Injection Pattern and after $this->collection->make([]) than new Collection

    use Illuminate\Support\Collection;
    ...
    // Inside of a clase.
    ...
    public function __construct(Collection $collection){
        $this->collection = $collection;
    }
    
    public function getResults(){
    ...
    $results = $this->collection->make([]);
    ...
    }
    

提交回复
热议问题