Collections - Laravel中文网 , laravel中文文档。Laravel 是一个具有表现力、优雅语法的 Web 应用程序框架. Laravel 是构建现代全栈 Web 应用程序的最佳选择.
如果集合中没有应该由 sole 方法返回的元素,则会抛出 \Illuminate\Collections\ItemNotFoundException 异常。 如果应该返回多个元素,则会抛出 \Illuminate\Collections\MultipleItemsFoundException。some()contains 方法的别名。sort()sort 方法对集合进行排序。 排序后的集合保留了原始数组键,因此在下面的示例中,我们将使用...
concat 方法为附加到原始 collection 的项目重新索引键。若要在关联 collections 中维护键,请参见 merge 方法。 contains() contains 方法确定 collection 是否包含给定项目。您可以传递一个闭包给 contains 方法来确定 collection 中是否存在与给定真实测试匹配的元素: ...
concat 方法在数字上重新索引连接到原始集合上的项目的键。要维护关联集合中的键,请参阅 merge 方法。contains()contains 方法确定集合是否包含给定项目。你可以将闭包传递给 contains 方法,以确定集合中是否存在与给定真值测试匹配的元素:$collection = collect([1, 2, 3, 4, 5]);$collection->contains(...
If there is more than one element that should be returned, an \Illuminate\Collections\MultipleItemsFoundException will be thrown.some()Alias for the contains method.sort()The sort method sorts the collection. The sorted collection keeps the original array keys, so in the following example...
If there are no elements in the collection that should be returned by the sole method, an \Illuminate\Collections\ItemNotFoundException exception will be thrown. If there is more than one element that should be returned, an \Illuminate\Collections\MultipleItemsFoundException will be thrown....
The merge method merges the given array or collection with the original collection. If a string key in the given items matches a string key in the original collection, the given items's value will overwrite the value in the original collection:...
You can cast multiple fields if needed. useDatomatic\EnumCollections\Casts\AsLaravelEnumCollection;useDatomatic\EnumCollections\EnumCollection;useIlluminate\Database\Eloquent\Model;classTestModelextendsModel {useHasEnumCollections;//Laravel 9/10protected$casts= ['field_name'=> AsLaravelEnumCollection::class...
19.Arrays as collections $devs = [ ['name' => 'Anouar Abdessalam', 'email' => '[email protected] '], ['name' => 'Bilal Ararou', 'email' => '[email protected]'] ]; $devs = new Illuminate\Support\Collection($devs); $devs->first(); $devs->last(); $devs->push(['name'...
9. Merge similar queries We sometimes need to make queries to retrieve different kinds of rows from the same table. 1$published_posts = Post::where('status','=','published')->get(); 2$featured_posts = Post::where('status','=','featured')->get(); ...