Laravel 5.6 中文文档return view('user.index', ['users' => $users]); } } get 方法返回包含结果集的 Illuminate\Support\Collection,其中每一个结果都是 PHP 的 StdClass 对象实例: 你可以像访问对象的属性一样访问字段的值: foreach ($users as $user) { echo 查询中使用查询构建器的所有方法。 集合 对 Eloquent 中获取多个结果的方法(比如 all 和 get)而言,其返回值是 Illuminate\Database\Eloquent\Collection 的一个实例, Collection 类提供了多个有用的函数来处理 Eloquent 结果集: $flights = $flights->reject(function ($flight) { return 中文学习资源:http://laravelacademy.org 176 Eloquent 返回的包含多条记录的结果集都是 Illuminate\Database\Eloquent\Collection 对象的实例,包括通过 get 方法或者通过访问关联关系 获取的结果。Eloquent 集合对象继承自 Laravel 的集合基类,因此很自然的继承了很多处理 Eloquent 模型底层数组的方法。0 码力 | 377 页 | 14.56 MB | 1 年前3
Laravel 5.1 中文文档$columns); // ... return $model; } lists 方法 lists 方法现在返回一个 Collection 实例而不是包含 Eloquent 查询结果的数组,如果你想 将 Collection 转化为数组,使用 all 方法: User::lists('id')->all(); 注意:Query Builder 的 lists 返回的仍然是数组。 6 Collection 类 sortBy 方法 sortBy 方法现在返回一个新的 collection 实例而不是改变已有的 collection: $collection = $collection->sortBy('name'); groupBy 方法 groupBy 方法现在为每个父级 Collection 中的 item 返回 Collection 实例,如果你想要将这些 map 方法实现: $collection->groupBy('type')->map(function($item){ return $item->all(); }); lists 方法 lists 方法现在返回一个 Collection 实例而不是数组,如果你想要将 Collection 转化数组,使 用 all 方法: $collection->lists('id')->all();0 码力 | 307 页 | 3.46 MB | 1 年前3
Laravel 6.0 中文文档RateLimited]; } 懒集合 许多开发者已经使用过 Laravel 功能强大的集合方法了,在 Laravel 6.0 中新引入了一个 LazyCollection 类来对 Collection 类进行 补充,LazyCollection 底层基于 PHP 的生成器实现,适用于处理 大型数据集。 例如,假设你的应用需要处理 GB 级别的日志文件,并使用 Laravel 的集 un.com 607 集合 简介 Illuminate\Support\Collection 类为处理数组数据提供了流式、 方便的封装。例如,查看下面的代码,我们使用辅助函数 collect 创 建一个新的集合实例,为每一个元素运行 strtoupper 函数,然后移 除所有空元素: $collection = collect(['taylor', 'abigail', null])->m 正如你所看到的,Collection 类允许你使用方法链对底层数组执行 匹配和移除操作,通常,每个 Collection 方法都会返回一个新 的 Collection 实例。 创建集合 正如上面所提到的,辅助函数 collect 为给定数组返回一个新 的 Illuminate\Support\Collection 实例,所以,创建集合很简单: $collection = collect([10 码力 | 1442 页 | 14.66 MB | 1 年前3
Laravel 5.2 中文文档建器的所有方法。 集合 对 Eloquent 中获取多个结果的方法(比如 all 和 get)而言,其返回值是 Illuminate\Database\Eloquent\Collection 的一个实例,Collection 类提供了多个有用 的函数来处理 Eloquent 结果。当然,你可以像操作数组一样简单循环这个集合: foreach ($flights as $flight) { comment!'; $comment->save(); 集合 1、简介 Eloquent 返回的所有的包含多条记录的结果集都 是 Illuminate\Database\Eloquent\Collection 对象的实例,包括通过 get 方法或者通过访 问关联关系获取的结果。Eloquent 集合对象继承自 Laravel 的集合基类,因此很自然的继 承了很多处理 Eloquent 模型底层数组的方法。 Eloquent 集合实例 * * @param array $models * @return \Illuminate\Database\Eloquent\Collection */ public function newCollection(array $models = []) { return new Cus0 码力 | 377 页 | 4.56 MB | 1 年前3
Laravel 5.3 中文文档3,并没有什么重大更新。 集合 key/value 顺序调整 集合方法 first, last 和 contains 都将“value”作为第一个参数传递给相应的回调闭包,例如: $collection->first(function ($value, $key) { return ! is_null($value); }); 在 Laravel 之前的版本中,$key 部分由网友 AC1982(微信号)提供翻译支持。 数据库 集合 查询构建器现在返回 Illuminate\Support\Collection 实例而不是原生数组,以便保持和 Eloquent 返回结果类型一致。 如果你不想要迁移查询构建器结果到 Collection 实例,可以在查询构建器的 get 方法后调用 call 方法,这将会返回原生的 PHP 数组结果,从而保证向后兼容: 集合序列化 Illuminate\Queue\SerializesModels trait 现 在 适 当 实 例 化 了 Illuminate\Database\Eloquent\Collection。对绝大多数应用来说这不算重大更新,但是,如果 你的应用绝对依赖于不是通过队列任务从数据库重新获取的集合,那么就要验证这一改动对应用 没有负面影响。 后台 woker 在使用 Artisan0 码力 | 691 页 | 9.37 MB | 1 年前3
Learning LaravelContains to check if a collection satisfies certain condition 32 Using Pluck to extract certain values from a collection 32 Using Map to manipulate each element in a collection 33 Using sum, avg, min min or max on a collection for statistical calculations 33 Sorting a collection 33 Sort() 33 SortBy() 34 SortByDesc() 35 Using reduce() 35 Using macro() to extend collections 36 Using Array Syntax 29 Chapter 8: Collections Syntax $collection = collect(['Value1', 'Value2', 'Value3']); // Keys default to 0, 1, 2, ..., • Remarks Illuminate\Support\Collection provides a fluent and convenient interface0 码力 | 216 页 | 1.58 MB | 1 年前3
Laravel 5.0 Documentation
Illuminate\Support\Collection class provides a fluent, convenient wrapper for working with arrays of data. For example, check out the following code. We'll use the collect helper to create a new collection instance instance from the array: $collection = collect(['taylor', 'abigail', null])->map(function($name) { return strtoupper($name); }) ->reject(function($name) { return is_null($value); }); As you can see the Collection class allows you to chain its methods to perform fluent mapping and reducing of the underlying array. In general, every Collection method returns an entirely new Collection instance0 码力 | 242 页 | 1.44 MB | 1 年前3
《Slides Dev Web》02. Introduction aux frameworks PHP
$routeInfo[2] ); } catch (Exception $e){ echo server_error($e); } break; } Framework PHP Une collection de bibliothèques avec un peu de glue. Un framework web vous propose une structure de base pour0 码力 | 24 页 | 1.03 MB | 1 年前3
Laravel 3.2 Documentationthat you may need to use Laravel on a host that does not allow you to update your DocumentRoot. A collection of algorithms to circumvent this need can be found on the Laravel forums. Basic Configuration0 码力 | 139 页 | 1.13 MB | 1 年前3
共 9 条
- 1













