Convert Figma logo to code with AI

tighten logocollect

A Collections-only split from Laravel's Illuminate Support

1,506
110
1,506
5

Top Related Projects

32,329

The Laravel Framework.

A set of useful Laravel collection macros

A Laravel package for multilingual models

[READ ONLY] Subtree split of the Illuminate Database component (see laravel/framework)

Quick Overview

Collect is a powerful and flexible data collection library for PHP. It provides a simple and intuitive API for working with various data sources, including arrays, objects, and databases. Collect is designed to be highly customizable and extensible, making it a great choice for a wide range of data-driven applications.

Pros

  • Flexible and Extensible: Collect supports a wide range of data sources and can be easily extended to work with new data sources.
  • Intuitive API: Collect's API is designed to be easy to use and understand, with a focus on providing a consistent and intuitive interface for working with data.
  • Powerful Functionality: Collect provides a wide range of functionality for working with data, including filtering, sorting, mapping, and reducing.
  • Efficient Performance: Collect is designed to be highly performant, with a focus on minimizing memory usage and maximizing processing speed.

Cons

  • Learning Curve: While Collect's API is designed to be intuitive, there may be a learning curve for developers who are new to the library.
  • Limited Documentation: The documentation for Collect could be more comprehensive, which may make it more difficult for new users to get started.
  • Dependency on PHP: Collect is a PHP-based library, which means that it may not be suitable for projects that are not written in PHP.
  • Limited Community: Collect has a relatively small community of users and contributors, which may make it more difficult to find support and resources.

Code Examples

Here are a few examples of how to use Collect:

// Creating a new collection from an array
$collection = collect([1, 2, 3, 4, 5]);

// Filtering the collection
$filteredCollection = $collection->filter(function ($item) {
    return $item > 2;
});

// Mapping the collection
$mappedCollection = $collection->map(function ($item) {
    return $item * 2;
});

// Reducing the collection
$reducedValue = $collection->reduce(function ($carry, $item) {
    return $carry + $item;
}, 0);
// Creating a new collection from an object
$collection = collect((object) [
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'age' => 30,
]);

// Accessing collection items
$name = $collection->get('name');
$email = $collection->get('email');
$age = $collection->get('age');
// Creating a new collection from a database result
$collection = collect(DB::table('users')->get());

// Filtering the collection
$filteredCollection = $collection->where('age', '>', 30);

// Sorting the collection
$sortedCollection = $collection->sortBy('name');

Getting Started

To get started with Collect, you can install it using Composer:

composer require tighten/collect

Once you have installed Collect, you can start using it in your PHP code:

use Tighten\Collect\Support\Collection;

$collection = new Collection([1, 2, 3, 4, 5]);
$filteredCollection = $collection->filter(function ($item) {
    return $item > 2;
});

// Output: [3, 4, 5]
print_r($filteredCollection->toArray());

For more information on using Collect, you can refer to the official documentation.

Competitor Comparisons

32,329

The Laravel Framework.

Pros of Laravel Framework

  • Comprehensive and feature-rich, providing a wide range of functionality out-of-the-box.
  • Extensive documentation and a large, active community, making it easier to find solutions and get support.
  • Robust and scalable, suitable for building complex web applications.

Cons of Laravel Framework

  • Larger codebase and more complex, which can make it more challenging for beginners to get started.
  • May be overkill for smaller projects that don't require the full suite of features.

Code Comparison

Collect

$collection = collect([1, 2, 3, 4, 5]);
$filtered = $collection->filter(function ($value) {
    return $value > 3;
});

Laravel Framework

$collection = collect([1, 2, 3, 4, 5]);
$filtered = $collection->filter(function ($value) {
    return $value > 3;
});

The code examples for Collect and Laravel Framework are nearly identical, demonstrating the similar functionality and ease of use between the two libraries.

A set of useful Laravel collection macros

Pros of spatie/laravel-collection-macros

  • Provides a wide range of useful collection macros, such as contains, containsAll, diff, diffAssoc, and more.
  • Actively maintained and regularly updated to support the latest Laravel versions.
  • Offers a comprehensive set of documentation and examples.

Cons of spatie/laravel-collection-macros

  • Requires the use of the Laravel framework, which may not be suitable for non-Laravel projects.
  • Some macros may overlap with the functionality provided by the core Laravel collection class.

Code Comparison

tighten/collect:

$collection = collect([1, 2, 3, 4, 5]);
$filtered = $collection->filter(function ($item) {
    return $item > 2;
});

spatie/laravel-collection-macros:

$collection = collect([1, 2, 3, 4, 5]);
$filtered = $collection->filter(function ($item) {
    return $item > 2;
});

As you can see, the code for both libraries is very similar, as they both utilize the core Laravel collection functionality.

A Laravel package for multilingual models

Pros of Astrotomic/laravel-translatable

  • Provides a simple and intuitive way to handle translations in Laravel applications.
  • Supports multiple translation models, allowing for more flexibility in managing translations.
  • Includes a comprehensive set of features, such as automatic translation fallback and translation caching.

Cons of Astrotomic/laravel-translatable

  • May have a steeper learning curve compared to Collect, especially for developers new to Laravel.
  • Requires additional setup and configuration to integrate with the application.
  • May have a larger footprint in terms of dependencies and overall package size compared to Collect.

Code Comparison

Astrotomic/laravel-translatable:

class Post extends Model
{
    use \Astrotomic\Translatable\Translatable;

    protected $fillable = ['title', 'content'];
    protected $translatedAttributes = ['title', 'content'];
}

Collect:

$data = collect([
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'age' => 30,
]);

$data->get('name'); // 'John Doe'

[READ ONLY] Subtree split of the Illuminate Database component (see laravel/framework)

Pros of illuminate/database

  • Provides a more comprehensive set of database-related features, including support for multiple database drivers, query builder, and database migrations.
  • Integrates well with other Illuminate components, making it a natural choice for Laravel-based projects.
  • Offers a more mature and feature-rich API compared to Collect.

Cons of illuminate/database

  • Larger in size and complexity compared to Collect, which may be overkill for simpler projects.
  • Requires more setup and configuration compared to Collect, which has a more straightforward usage.
  • May have a steeper learning curve for developers not familiar with the Illuminate ecosystem.

Code Comparison

Collect

$collection = collect([1, 2, 3, 4, 5]);
$filtered = $collection->filter(function ($value) {
    return $value > 3;
});

illuminate/database

$users = DB::table('users')
           ->where('active', 1)
           ->orderBy('name', 'desc')
           ->get();

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Tighten Collect Logo Banner

Collect - Illuminate Collections

Latest Version on Packagist Total Downloads Build Status

Deprecated: With the separation of Illuminate's Collections package, Collect is no longer necessary :tada: . We will maintain it for the 8.0 and 9.0 releases of Laravel for the convenience of package maintainers, and will stop mirroring new major versions after 9.0, but keep the existing package here for continued support.

Import Laravel's Collections into non-Laravel packages easily, without needing to require the entire Illuminate\Support package. (Why not pull Illuminate\Support in framework-agnostic packages)

Written by Taylor Otwell as a part of Laravel's Illuminate/Support package, Collect is just the code from Support needed in order to use Collections on their own.

Lovingly split by Matt Stauffer for Tighten Co., with a kick in the butt to finally do it from @assertchris.

Installation

With Composer:

composer require tightenco/collect

Development

If you are a developer working on Collect and you're tasked with upgrading it to mirror a new version of Laravel, run ./upgrade.sh from the root directory. You can pass a parameter to target a specific Laravel version (e.g. ./upgrade.sh 5.7.10) or, if you don't pass a parameter, the script will find the latest tagged release and run against that.

The upgrader will pull down the appropriate source and test files for the specified version of Laravel and then run the tests.

./upgrade.sh
# or
./upgrade.sh 5.7.10

The upgrade script requires the use of wget. It's recommended to install homebrew, and run brew install wget

Testing

Due to a dependency on Carbon, tests won't pass until you've run ./upgrade.sh at least once locally.

vendor/bin/phpunit

FAQ

  • Has this ever, or will it ever, develop independently from Illuminate's Collections? No. Using an upgrade script, it's split automatically with every Laravel release to keep it in sync with Laravel's Collections, even mirroring the release numbers.
  • Why is the package tightenco/collect instead of illuminate/collect? It's not an official Laravel package so we don't want to use the Packagist namespace reserved by Laravel packages. One day Collection may be extracted from illuminate/support to a new package. If so, we'll deprecate this package and point to the core version. Now that illuminate/collections has been released, we're deprecating this package.
  • Why not just use an array? What a great question. Tighten alum Adam Wathan has a book about that.

License

The Laravel framework is open-sourced software licensed under the MIT license. Collect consists almost entirely of Laravel source code, so maintains the same license.