Download the PHP package teksite/handler without Composer
On this page you can find all versions of the php package teksite/handler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download teksite/handler
More information about teksite/handler
Files in teksite/handler
Package handler
Short Description Some features to work with error handling in Laravel codes
License MIT
Informations about the package handler
Handler Package
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
- About
- Author
- Contact
- Installation
- Features
- Event System
- Configuration
- Support
About
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
Developed by Sina Zangiband.
Contact
- Website:
- teksite.net
- laratek.net
- laratek.ir
- Email: [email protected]
Installation
Step 1: Install via Composer
Run the following command in your terminal:
bash composer require teksite/handler
Step 2: Register the Service Provider
For Laravel > 9
Add the service provider to the bootstrap/providers.php file:
Note: Laravel 5.5 and above supports auto-discovery, so this step is not required for newer versions.
Features
Simplify exception handling with ServiceWrapper
Teksite\Handler\Actions\ServiceWrapper
Basic Usage
- 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
Event Dispatching
The run() method accepts two optional parameters to dispatch custom events:
Example:
Event Classes Configuration:
Define your event classes in config/handler.php:
Note: Events are resolved using Laravel's service container, so dependency injection is fully supported in your event constructors.
ServiceResult Wrapper
By default, the output of both do() and ifFailed() is wrapped in a ServiceResult instance for consistent return values:
Disable wrapping:
Streamlined Database Query Methods
Teksite\Handler\Facade\FetchData (backed by Teksite\Handler\Services\FetchDataService)
FetchDataService is resolved from the container (it depends on the current Request), so use the
FetchData facade or dependency injection - it is not a static class.
Example with ServiceWrapper
Standalone Usage
Fluent Usage
Every option can also be set fluently before calling get(), which is handy when the same query is
built up conditionally:
Method Parameters
Search with Operators:
Once you're done with a shared/injected instance, resetOnly(), resetWith(), resetWithCount(),
resetSearch(), resetOrdering(), resetPagination() and reset() clear the fluent state so it can
be reused for a different query. forgetColumnsCache($model) and forgetAllColumnsCache() clear the
cached column listing used to validate orderBy() input (this is also flushed automatically after
migrations run).
HTTP Response Helper
Event System
How It Works
The ServiceWrapper automatically dispatches events when configured:
- Success Events - Triggered when the do() closure executes without errors
- Failure Events - Triggered when an exception is caught
Custom Event Example
Create your event class:
Configure in config/handler.php:
Use in your codes:
Advanced Event Dispatching
Control event dispatch per method call:
Configuration
Publish Configuration File
Support
For questions, issues, or feature requests, please reach out via:
- Website: teksite.net | laratek.net
- Email: [email protected]
- GitHub Issues: teksite/handler
Contributions are welcome! Feel free to submit a pull request or open an issue on GitHub.