PHPackages                             teksite/handler - 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. [Framework](/categories/framework)
4. /
5. teksite/handler

ActiveLibrary[Framework](/categories/framework)

teksite/handler
===============

Some features to work with error handling in Laravel codes

2.1.7(1mo ago)1502MITPHPPHP ^8.3

Since Jan 17Pushed 3w ago1 watchersCompare

[ Source](https://github.com/teksite/handler)[ Packagist](https://packagist.org/packages/teksite/handler)[ RSS](/packages/teksite-handler/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (7)Versions (20)Used By (2)

Handler Package
===============

[](#handler-package)

About
-----

[](#about)

A lightweight Laravel package designed to simplify common PHP and Laravel operations, including try-catch handling, database querying, and other utility functions.

Table of Contents
-----------------

[](#table-of-contents)

- [About](#about)
- [Author](#author)
- [Contact](#contact)
- [Installation](#installation)
- [Features](#features)
- [Event System](#event-system)
- [Configuration](#configuration)
- [Support](#support)

About
-----

[](#about-1)

The Handler Package streamlines development by providing helper functions for managing try-catch blocks, fetching data from databases, and other common tasks in PHP and Laravel applications. It aims to reduce boilerplate code and improve code readability.

Author
------

[](#author)

Developed by Sina Zangiband.

Contact
-------

[](#contact)

- Website:
    - teksite.net
    - laratek.net
    - laratek.ir
- Email:

---

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

[](#installation)

### Step 1: Install via Composer

[](#step-1-install-via-composer)

Run the following command in your terminal:

bash composer require teksite/handler

### Step 2: Register the Service Provider

[](#step-2-register-the-service-provider)

#### For Laravel &gt; 9

[](#for-laravel--9)

Add the service provider to the bootstrap/providers.php file:

```
'providers' => [
// Other Service Providers
Teksite\Handler\ServiceProvider::class,
],
```

Note: Laravel 5.5 and above supports auto-discovery, so this step is not required for newer versions.

Features
--------

[](#features)

### Simplify exception handling with ServiceWrapper

[](#simplify-exception-handling-with-servicewrapper)

`Teksite\Handler\Actions\ServiceWrapper`

#### Basic Usage

[](#basic-usage)

```
return ServiceWrapper::make()->do(function () {
// your code
})->ifFailed(function () {
// in case your code failed
})->run();
```

- do() is required - contains your main code to be processed in try-catch
- ifFailed() is optional - runs if your code fails, errors are automatically logged to laravel.log

#### Advanced Configuration

[](#advanced-configuration)

```
// Disable error handling wrapper
ServiceWrapper::make(withHandler: false)->do(fn() => $this->someMethod())->run();

// Disable database transaction (enabled by default)
ServiceWrapper::make(hasTransaction: false)->do(fn() => $this->someMethod())->run();

// Disable ServiceResult wrapping (enabled by default)
ServiceWrapper::make(wrapServiceResult: false)->do(fn() => $this->someMethod())->run();
```

#### Event Dispatching

[](#event-dispatching)

The `run()` method accepts two optional parameters to dispatch custom events:

```
public function run(bool $dispatchSuccessEvent = false, bool $dispatchFailureEvent = true): mixed
```

Example:

```
return ServiceWrapper::make()
->do(function () {
// Your business logic
return User::create($request->validated());
})
->ifFailed(function () {
// Fallback logic
return ['error' => 'User creation failed'];
})
->run(
dispatchSuccessEvent: true,  // Dispatches success event on completion
dispatchFailureEvent: false  // Disables failure event dispatch
);
```

Event Classes Configuration:
----------------------------

[](#event-classes-configuration)

Define your event classes in config/handler-settings.php:

```
return [
// ... other configurations

    'success_event_class' => "Teksite\\Handler\\Events\\OnSuccessEvent",
    'failure_event_class' => "Teksite\\Handler\\Events\\OnFailureEvent",
];
```

Note: Events are resolved using Laravel's service container, so dependency injection is fully supported in your event constructors.

#### ServiceResult Wrapper

[](#serviceresult-wrapper)

By default, the output of both do() and ifFailed() is wrapped in a ServiceResult instance for consistent return values:

```
$result = ServiceWrapper::make()->do(fn() => Post::find(1))->run();

if ($result->isSuccess()) {
$post = $result->getData();
} else {
$error = $result->getData(); // Error information
}
```

Disable wrapping:

```
$rawResult = ServiceWrapper::make(wrapServiceResult: false)->do(fn() => Post::find(1))->run();
```

### Streamlined Database Query Methods

[](#streamlined-database-query-methods)

`Teksite\Handler\Services\FetchDataService`

#### Example with ServiceWrapper

[](#example-with-servicewrapper)

```
public function get(mixed $fetchData = [])
{
return ServiceWrapper::make()
->do(function () use ($fetchData) {
return FetchDataService::get(Post::class, ['title'], ...$fetchData);
})
->ifFailed(function () {
// Handle failure
})
->run(dispatchSuccessEvent: true);
}
```

#### Standalone Usage

[](#standalone-usage)

```
// Without ServiceWrapper
$posts = FetchDataService::get(Post::class, ['title']);
```

#### Method Parameters

[](#method-parameters)

```
FetchDataService::get(
string|Closure|Builder|Relation $model,  // Model class, query builder, or relation
string|array|Closure|null $searchColumns, // Search columns with operators
array $only = ['*'],                       // Columns to select
null|int|false $perPage = null,            // Items per page (pagination)
null|false|int $limitPagination = null     // Maximum items per page limit
);
```

Search with Operators:

```
$searchColumns = [
['column' => 'title', 'operator' => 'LIKE'],
['column' => 'category', 'operator' => '='],
'status' // Simple column search (default '=')
];
```

### HTTP Response Helper

[](#http-response-helper)

```
use Teksite\Handler\Services\ResponderServices;

// Success response
$response = ResponderServices::success('Well done!', ['post' => $post], 201);

// Failure response
$response = ResponderServices::failed('Something went wrong', ['auth' => 'forbidden'], 500);

// Redirect as HTTP response
$response->go();

// Return as JSON response (for APIs and AJAX)
$response->reply();
```

Event System
------------

[](#event-system)

### How It Works

[](#how-it-works)

The ServiceWrapper automatically dispatches events when configured:

1. Success Events - Triggered when the do() closure executes without errors
2. Failure Events - Triggered when an exception is caught

### Custom Event Example

[](#custom-event-example)

Create your event class:

```
namespace App\Events;

use Illuminate\Foundation\Events\Dispatchable;

class UserCreationSucceeded
{
use Dispatchable;

    public function __construct(public $user)
    {
        //
    }
}
```

Configure in config/handler-settings.php:

```
'success_event_class' => \App\Events\UserCreationSucceeded::class,
```

Use in your codes:

```
ServiceWrapper::make()
->do(fn() => User::create($data))
->run(dispatchSuccessEvent: true);
```

### Advanced Event Dispatching

[](#advanced-event-dispatching)

Control event dispatch per method call:

```
// Dispatch only success event
$wrapper->run(dispatchSuccessEvent: true, dispatchFailureEvent: false);

// Dispatch only failure event (default behavior)
$wrapper->run(dispatchSuccessEvent: false, dispatchFailureEvent: true);

// Dispatch both
$wrapper->run(dispatchSuccessEvent: true, dispatchFailureEvent: true);

// Dispatch none
$wrapper->run(dispatchSuccessEvent: false, dispatchFailureEvent: false);
```

Configuration
-------------

[](#configuration)

### Publish Configuration File

[](#publish-configuration-file)

```
php artisan vendor:publish --provider="Teksite\Handler\ServiceProvider"
```

Support
-------

[](#support)

For questions, issues, or feature requests, please reach out via:

- Website: teksite.net | laratek.net
- Email:
- GitHub Issues: teksite/handler

Contributions are welcome! Feel free to submit a pull request or open an issue on GitHub.

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance95

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~29 days

Recently: every ~1 days

Total

18

Last Release

34d ago

Major Versions

v0.0.2 → 1.0.02025-05-05

1.1.1 → v2.x-dev2026-04-26

PHP version history (2 changes)0.0.1PHP ^8.2

v2.x-devPHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/149485086?v=4)[teksite](/maintainers/teksite)[@teksite](https://github.com/teksite)

---

Top Contributors

[![teksite](https://avatars.githubusercontent.com/u/149485086?v=4)](https://github.com/teksite "teksite (36 commits)")

### Embed Badge

![Health badge](/badges/teksite-handler/health.svg)

```
[![Health](https://phpackages.com/badges/teksite-handler/health.svg)](https://phpackages.com/packages/teksite-handler)
```

###  Alternatives

[laravel/octane

Supercharge your Laravel application's performance.

4.0k26.6M223](/packages/laravel-octane)[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[code16/sharp

Laravel Content Management Framework

79164.7k8](/packages/code16-sharp)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21318.6k3](/packages/ecotone-laravel)[codewithdennis/larament

Larament is a time-saving starter kit to quickly launch Laravel 13.x projects. It includes FilamentPHP 5.x pre-installed and configured, along with additional tools and features to streamline your development workflow.

3991.8k](/packages/codewithdennis-larament)[r2luna/brain

Brain: A process-driven architecture alternative for your Laravel Application.

6338.7k1](/packages/r2luna-brain)

PHPackages © 2026

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