1- ** This project is currently in the testing phase and may undergo changes.**
2-
31# Hawk Laravel
42
5- Laravel errors Catcher for [ Hawk.so] ( https://hawk.so ) .
3+ [ ![ Latest Version on Packagist] ( https://img.shields.io/packagist/v/codex-team/hawk.laravel.svg?style=flat-square )] ( https://packagist.org/packages/codex-team/hawk.laravel )
4+ [ ![ License] ( https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square )] ( LICENSE )
5+ [ ![ PHP Version] ( https://img.shields.io/packagist/php-v/codex-team/hawk.laravel?style=flat-square )] ( https://www.php.net/ )
6+
7+ Laravel error catcher for [ Hawk.so] ( https://hawk.so ) .
68
79## Setup
810
9- 1 . [ Register ] ( https://garage.hawk.so/sign-up ) an account, create a Project and get an Integration Token.
11+ ---
1012
11- 2 . Install SDK via [ composer] ( https://getcomposer.org ) to install the Catcher
13+ 1 . [ Register] ( https://garage.hawk.so/sign-up ) an account, create a project, and get an ** Integration Token** .
14+ 2 . Install the SDK via [ Composer] ( https://getcomposer.org ) :
1215
13- - Catcher provides support for PHP 7.2 or later
14- - Your Laravel version needs to be 11.x or higher
16+ ``` bash
17+ composer require codex-team/hawk.laravel
18+ ```
1519
16- ### Install command
20+ ### Requirements
1721
18- ``` bash
19- $ composer require codex-team/hawk.laravel
20- ```
22+ - PHP ** 7.2+**
23+ - Laravel ** 11.x+**
24+
25+ ## Features
26+
27+ ---
2128
22- To enable capturing unhandled exceptions for reporting to ` Hawk ` , modify your ` bootstrap/app.php ` file as follows:
29+ - 🦅 Automatic error catching
30+ - 💎 Manual exception and message sending
31+ - 🙂 Attaching user information
32+ - 📦 Attaching additional context
33+ - 🛡️ Sensitive data filtering
34+ - 🌟 BeforeSend hook for event preprocessing
35+ - 🗂️ Breadcrumbs collection (routes, queries, jobs, logs)
36+ - ⚡ Laravel 11+ support
37+
38+ ## Configuration
39+
40+ ---
41+
42+ ### Enable exception capturing
43+
44+ Update your ` bootstrap/app.php ` :
2345
2446``` php
2547<?php
@@ -39,12 +61,13 @@ return Application::configure(basePath: dirname(__DIR__))
3961 })
4062 ->withExceptions(function (Exceptions $exceptions) {
4163 HawkBundle\Integration::handles($exceptions);
42- })->create();
64+ })
65+ ->create();
4366```
4467
4568### Register the Service Provider
4669
47- To complete the setup, add the ` Hawk ` service provider to your ` config/app.php ` or ` bootstrap/providers.php ` file in the providers array :
70+ Add the ` Hawk ` service provider to your ` config/app.php ` or ` bootstrap/providers.php ` :
4871
4972``` php
5073'providers' => [
@@ -53,34 +76,143 @@ To complete the setup, add the `Hawk` service provider to your `config/app.php`
5376],
5477```
5578
56- ### Configuration
79+ ### Publish configuration
5780
58- Set up Hawk using the following command :
81+ Run :
5982
6083``` bash
61- $ php artisan hawkbundle:publish
84+ php artisan hawkbundle:publish
6285```
6386
64- This will create the configuration file (` config/hawk.php ` ), and you can manually add the ` HAWK_TOKEN ` in your ` .env ` file:
87+ This will create ` config/hawk.php ` .
88+ Then add your token in ` .env ` :
6589
6690``` env
67- HAWK_TOKEN=<your integration token>
91+ HAWK_TOKEN=<your_integration_token>
92+ ```
93+
94+ ## Usage
95+
96+ ---
97+
98+ ### Adding User & Context Information
99+
100+ ``` php
101+ app(\HawkBundle\Catcher::class)->setUser([
102+ 'name' => 'John Doe',
103+ 'photo' => 'https://example.com/avatar.png',
104+ ]);
105+
106+ app(\HawkBundle\Catcher::class)->setContext([
107+ 'page' => 'checkout',
108+ 'cart_id' => 123,
109+ ]);
110+ ```
111+
112+ ### Sending Exceptions Manually
113+
114+ Inject ` \HawkBundle\Catcher ` and call ` sendException ` :
115+
116+ ``` php
117+ use HawkBundle\Catcher;
118+
119+ class TestController extends Controller
120+ {
121+ private Catcher $catcher;
122+
123+ public function __construct(Catcher $catcher)
124+ {
125+ $this->catcher = $catcher;
126+ }
127+
128+ public function test()
129+ {
130+ try {
131+ // Code that may fail
132+ } catch (\Exception $e) {
133+ $this->catcher->sendException($e);
134+ }
135+ }
136+ }
68137```
69138
70- ## Issues and improvements
139+ ### Sending Custom Messages
71140
72- Feel free to ask questions or improve the project.
141+ ``` php
142+ app(\HawkBundle\Catcher::class)->sendMessage(
143+ 'Checkout started',
144+ [
145+ 'cart_id' => 123,
146+ 'step' => 'payment',
147+ ]
148+ );
149+ ```
150+
151+ ## BeforeSend Hook
152+
153+ ---
154+
155+ If you want to modify or filter errors before they are sent to Hawk,
156+ implement the ` BeforeSendServiceInterface ` .
157+
158+ Example:
159+
160+ ``` php
161+ <?php
162+
163+ namespace App\Hawk;
164+
165+ use Hawk\EventPayload;
166+ use HawkBundle\Services\BeforeSendServiceInterface;
73167
74- ## Links
168+ class BeforeSendService implements BeforeSendServiceInterface
169+ {
170+ public function __invoke(EventPayload $eventPayload): ?EventPayload
171+ {
172+ $user = $eventPayload->getUser();
75173
76- Repository: https://github.com/codex-team/hawk.laravel
174+ // Remove sensitive data
175+ if (!empty($user['email'])) {
176+ unset($user['email']);
177+ $eventPayload->setUser($user);
178+ }
77179
78- Report a bug: https://github.com/codex-team/hawk.laravel/issues
180+ // Skip sending in specific cases
181+ if ($eventPayload->getContext()['skip_sending'] ?? false) {
182+ return null;
183+ }
79184
80- Composer Package: https://packagist.org/packages/codex-team/hawk.laravel
185+ return $eventPayload;
186+ }
187+ }
188+ ```
189+
190+ Register it in ` config/hawk.php ` :
191+
192+ ``` php
193+ return [
194+ 'integration_token' => env('HAWK_TOKEN'),
195+ 'before_send_service' => \App\Hawk\BeforeSendService::class,
196+ ];
197+ ```
198+
199+ ## Issues & Contributions
81200
82- CodeX Team: https://codex.so
201+ ---
202+
203+ - Found a bug? [ Open an issue] ( https://github.com/codex-team/hawk.laravel/issues )
204+ - Want to improve the package? Pull requests are welcome!
205+
206+ ## Useful Links
207+
208+ ---
209+
210+ - ** Repository:** [ github.com/codex-team/hawk.laravel] ( https://github.com/codex-team/hawk.laravel )
211+ - ** Composer Package:** [ packagist.org/packages/codex-team/hawk.laravel] ( https://packagist.org/packages/codex-team/hawk.laravel )
212+ - ** CodeX Team:** [ codex.so] ( https://codex.so )
83213
84214## License
85215
86- MIT
216+ ---
217+
218+ [ MIT] ( LICENSE )
0 commit comments