isswp101 / collection by isswp101

This package allows you to update laravel collections by query
6
1
1
Package Data
Maintainer Username: isswp101
Maintainer Contact: isswp101@gmail.com (Sergey Sorokin)
Package Create Date: 2016-03-02
Package Last Update: 2016-03-04
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2020-03-31 03:13:32
Package Statistics
Total Downloads: 6
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 1
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

Laravel Collection Updater

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

This package provides you with a convenient syntax to update laravel collections by query.

Install

Via Composer

$ composer require isswp101/collection

Usage

use Isswp101\Collection\Collection;
use Isswp101\Collection\Query;

$collection = new Collection([
    ['aaa' => 100, 'bbb' => 200, 'ccc' => 300],
    ['aaa' => 100, 'bbb' => 201, 'ccc' => 300],
    ['aaa' => 100, 'bbb' => 201, 'ccc' => 301],
    ['aaa' => 101, 'bbb' => 201, 'ccc' => 301],
]);

$query = (new Query())->where('aaa', 100)->where('bbb', 201);

$collection->update($query, 'ccc', 0);

var_dump($collection->all());

// Output
// [
//   ['aaa' => 100, 'bbb' => 200, 'ccc' => 300],
//   ['aaa' => 100, 'bbb' => 201, 'ccc' => 0],
//   ['aaa' => 100, 'bbb' => 201, 'ccc' => 0],
//   ['aaa' => 101, 'bbb' => 201, 'ccc' => 301],
// ];

$collection->update($query, ['ccc' => 0]); // value as array

Methods

Class Isswp101\Collection\Query

  • where($key, $value, $strict = true)
  • whereNot($key, $value, $strict = true)
  • whereLoose($key, $value)
  • whereNotLoose($key, $value)
  • whereIn($key, $array, $strict = true)
  • whereNotIn($key, $array, $strict = true)

Class Isswp101\Collection\Collection

  • update(Query $query, $key, $value = null) -- Update items according to the obtained conditions.
  • filterByQuery(Query $query) -- Filter items according to the obtained conditions.
  • firstByQuery(Query $query) -- Get the first item from the collection according to the obtained conditions
  • lastByQuery(Query $query) -- Get the last item from the collection according to the obtained conditions.

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email isswp101@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.