Laravel 8 pipeInto() {#collection-method}
2021-07-01 16:33 更新
pipeInto
方法创建一个给定类的新实例,并将集合传递给构造函数:
class ResourceCollection
{
/**
* The Collection instance.
*/
public $collection;
/**
* Create a new ResourceCollection instance.
*
* @param Collection $resource
* @return void
*/
public function __construct(Collection $collection)
{
$this->collection = $collection;
}
}
$collection = collect([1, 2, 3]);
$resource = $collection->pipeInto(ResourceCollection::class);
$resource->collection->all();
// [1, 2, 3]
以上内容是否对您有帮助:
更多建议: