PHPackages                             chiiya/laravel-utilities - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. chiiya/laravel-utilities

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

chiiya/laravel-utilities
========================

Common utilities for laravel projects

5.7.2(3mo ago)16.4k↓42.6%1MITPHPPHP ^8.2CI passing

Since Dec 17Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/chiiya/laravel-utilities)[ Packagist](https://packagist.org/packages/chiiya/laravel-utilities)[ Docs](https://github.com/chiiya/laravel-utilities)[ GitHub Sponsors](https://github.com/chiiya)[ RSS](/packages/chiiya-laravel-utilities/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (7)Versions (36)Used By (1)

Laravel Utilities
=================

[](#laravel-utilities)

[![Latest Version on Packagist](https://camo.githubusercontent.com/16e48447cf80f2684b7fec10c7ae10527ececfa4af3ac32ab595faae438a178c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6368696979612f6c61726176656c2d7574696c69746965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chiiya/laravel-utilities)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/30a511c501e26bafe6d4a13b9de3ef263da88191990307bcccd43b145e65b1c5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6368696979612f6c61726176656c2d7574696c69746965732f6c696e743f6c6162656c3d636f64652532307374796c65)](https://github.com/chiiya/laravel-utilities/actions?query=workflow%3Alint+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/ae23af8f617f75f024993ec198b973851a21f07bc322035338fe05ae60da8367/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6368696979612f6c61726176656c2d7574696c69746965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chiiya/laravel-utilities)

Common classes and utilities for Laravel projects.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require chiiya/laravel-utilities
```

You can optionally publish the config file with:

```
php artisan vendor:publish --tag="utilities-config"
```

This is the contents of the published config file:

```
return [
    /*
    |--------------------------------------------------------------------------
    | Temporary path
    |--------------------------------------------------------------------------
    | Used for downloads and unzipping files.
    */
    'tmp_path' => storage_path('tmp'),
];
```

Usage
-----

[](#usage)

 `TimedCommand` - Print command execution time
Simple extension of the Laravel `Command` that prints execution time after completion.

```
use Chiiya\Common\Commands\TimedCommand;

class SendEmails extends TimedCommand
{
    protected $signature = 'mail:send {user}';

    public function handle(DripEmailer $drip)
    {
        $drip->send(User::find($this->argument('user')));
    }
```

```
$ php artisan mail:send 1
> Execution time: 0.1s
```

 `SetsSender` - Set sender for mailables
Trait to set the sender (return path) for mailables for e.g. bounce handling.

```
use Chiiya\Common\Mail\SetsSender;

class OrderShipped extends Mailables
{
    use SetsSender;

    public function build(): self
    {
        return $this
            ->subject('Order shipped')
            ->markdown('emails.orders.shipped')
            ->sender('return@example.com');
    }
}
```

 `PresentableTrait` - View presenters for eloquent models
View presenter similar to the no longer maintained [`laracasts/presenter`](https://github.com/laracasts/Presenter)package. Useful for doing some manipulations before displaying data.

```
use Chiiya\Common\Presenter\Presenter;

/** @extends Presenter */
class UserPresenter extends Presenter
{
    public function name(): string
    {
        return $this->first_name.' '.$this->last_name;
    }
}
```

```
use Chiiya\Common\Presenter\PresentableTrait;

class User extends Model
{
    /** @use PresentableTrait */
    use PresentableTrait;

    protected string $presenter = UserPresenter::class;
}
```

```
Hello, {{ $user->present()->name }}
```

 `AbstractRepository` - Base repository for the repository pattern
Base repository for usage of the repository pattern. It provides `get`, `find`, `index`, `search`, `count`, `create`, `update` and `delete` methods for the configured `$model`. Most methods accept an optional `$filters` parameter, that may be used to apply the filters configured in the `applyFilters` method to your queries.

A general recommendation is to only use repositories as a place to store your complex queries and/or queries that are used repeatedly in multiple places, since otherwise they might be considered an anti-pattern. For more complex queries it can however be useful to separate them from your services. Repositories also serve as a way to self-document those queries by using descriptive method names. This way developers don't have to parse database queries and try to understand their purpose when going through your application logic.

```
use Chiiya\Common\Repositories\AbstractRepository;

/**
 * @extends AbstractRepository
 */
class PostRepository extends AbstractRepository
{
    protected string $model = Post::class;

    /**
     * @return Collection
     */
    public function postsDiscussedYesterday()
    {
        return $this->newQuery()
            ->whereHas('comments', function (Builder $builder) {
                $builder
                    ->where('created_at', '>=', now()->subDay()->startOfDay())
                    ->where('created_at', 'service->import(storage_path('app/exports'));
        // Generate specified amount of random codes using the given pattern and character set
        $this->service->generate(
            1_000_000,
            '####-####-####',
            CodeService::SET_NUMBERS_AND_UPPERCASE,
        );
        // Get generated codes for further processing
        $codes = $this->service->getCodes();
        // ... e.g. bulk insert $codes into database
        // Export newly generated codes into (batched) CSV files. Optionally specify the amount of codes per file
        $this->service->export(storage_path('app/exports'));
        $this->service->export(path: storage_path('app/exports'), perFile: 500_000);
    }
}
```

 `CsvReader` - Read CSV files
Small wrapper around the [`openspout/openspout`](https://github.com/openspout/openspout) csv reader for high-performance reading of CSV files:

```
$reader = resolve(\Chiiya\Common\Services\CsvReader::class);
$reader->open('/path/to/file.csv');
foreach ($reader->rows() as $row) {
    $values = $row->toArray();
}
$reader->close();
```

 `CsvWriter` - Write CSV files
Small wrapper around the [`openspout/openspout`](https://github.com/openspout/openspout) csv writer:

```
$writer = resolve(\Chiiya\Common\Services\CsvWriter::class);
$writer->open('/path/to/file.csv');
$writer->write(['Value 1', 'Value 2']);
$writer->close();
```

 `ExcelReader` - Read XLS/XLSX files
Small wrapper around the [`openspout/openspout`](https://github.com/openspout/openspout) excel reader for high-performance reading of XLS/XLSX files:

```
$reader = resolve(\Chiiya\Common\Services\ExcelReader::class);
$reader->open('/path/to/file.xlsx');
foreach ($reader->getSheetIterator() as $sheet) {
    foreach ($sheet->getRowIterator() as $row) {
        $values = $row->toArray();
    }
}
$reader->close();
```

 `ExcelWriter` - Write XLX/XLSX files
Small wrapper around the [`openspout/openspout`](https://github.com/openspout/openspout) excel writer:

```
$writer = resolve(\Chiiya\Common\Services\ExcelWriter::class);
$writer->open('/path/to/file.xlsx');
$writer->setCurrentSheetName('Sheet 1');
$writer->addHeaderRow(['Name', 'Email']);
$writer->write(['John Doe', 'john.doe@example.com']);
$writer->addSheet('Sheet 2');
$writer->write(['Value 1', 'Value 2']);
$writer->close();
```

 `FileDownloader` - Download remote files
Utility class for downloading files from a remote URL.

```
$downloader = resolve(\Chiiya\Common\Services\FileDownloader::class);
$file = $downloader->download('https://example.com/path/to/file.txt');
dump($file->getPath());
$file->delete();
```

 `Zipper` - Zip and unzip .zip files
Utility class for zipping and unzipping .zip files.

```
// Unzipping
$zipper = resolve(\Chiiya\Common\Services\Zipper::class);
$location = $zipper->unzip('/path/to/file.zip');

// Zipping
$zipper->create('documents.zip')->addDirectory('/path/to/directory')->close();
$path = $zipper->getZipPath();

// Or with files
$zipper
    ->create('documents.zip')
    ->addFiles([
        '/path/to/file1',
        '/path/to/file2',
    ])
    ->close();
$path = $zipper->getZipPath();
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance83

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 69.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~58 days

Recently: every ~17 days

Total

33

Last Release

118d ago

Major Versions

1.5.0 → 2.0.02021-12-10

2.1.0 → 3.0.02022-02-22

3.1.0 → 4.0.02022-03-22

4.5.0 → 5.0.02023-01-10

PHP version history (4 changes)1.0.0PHP ^7.2|^8.0

2.0.0PHP ^8.0

4.0.0PHP ^8.1

5.2.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/34a7cd6c6e8c5fd30b6cd28645c3384f343fc90d10b0df8c80c7ad424e3dba2a?d=identicon)[chiiya](/maintainers/chiiya)

---

Top Contributors

[![chiiya](https://avatars.githubusercontent.com/u/15029301?v=4)](https://github.com/chiiya "chiiya (62 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (18 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (9 commits)")

---

Tags

laravelcommonutilities

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/chiiya-laravel-utilities/health.svg)

```
[![Health](https://phpackages.com/badges/chiiya-laravel-utilities/health.svg)](https://phpackages.com/packages/chiiya-laravel-utilities)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.8k28.9M627](/packages/spatie-laravel-data)[maestroerror/laragent

Power of AI Agents in your Laravel project

630106.4k](/packages/maestroerror-laragent)[nativephp/mobile

NativePHP for Mobile

82724.0k43](/packages/nativephp-mobile)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[spatie/laravel-rdap

Perform RDAP queries in a Laravel app

72108.3k2](/packages/spatie-laravel-rdap)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
