Download the PHP package binarcode/laravel-developer without Composer
On this page you can find all versions of the php package binarcode/laravel-developer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download binarcode/laravel-developer
More information about binarcode/laravel-developer
Files in binarcode/laravel-developer
Package laravel-developer
Short Description Lightweight package to log slack exceptions.
License MIT
Homepage https://github.com/binarcode/laravel-developer
Informations about the package laravel-developer
Lightweight package help your development eyes.
Installation
You can install the package via composer:
You can publish and run the migrations with:
You can publish the config file with:
This is the contents of the published config file:
Additionally, you must create a Slack App for your Slack workspace.
If you only need to send notifications to the same Slack workspace that the App is created in, you should ensure that your App has the chat:write
, chat:write.public
, and chat:write.customize
scopes. These scopes can be added from the "OAuth & Permissions" App management tab within Slack.
Usage
Send exception to slack
The simplies way to use the package is to send an exception to the slack:
Or using helper:
Send message to slack
Use this to send any message to your dev slack:
Or using helper:
Send anything to slack
Obviously, you can send any kind of message to the slack channel. The toDevSlack
method accept an instance of DevNotificationDto
:
Persist exception
If you want to persist the exception into the database, in any place you want to catch and log an exception, you can do something like this:
Under the hood, the package will store an entry in the exception_logs
of your database with the exception.
Or using helper (but this will also send a slack notification):
Slack notification
If you want to send the notification to the slack webhook, just call the
notifyDevs()
method on your ExceptionLog
instance.
This will send a slack notification to the incoming webhook you have specified in the developer.slack_dev_hook
configuration file.
Passing other payload
You can specify payload to your exception, so it will be stored along with the exception. In the example bellow we will catch a Cashier
exception and will log it:
The second $e->payment->asStripePaymentIntent()
object MUST implement the \JsonSerializable()
interface.
You can add more payloads by using:
Using a custom notification
However, Laravel Developer package provides you the Binarcode\LaravelDeveloper\Notifications\DevNotification
notification, you are free to use a completely new one by configuring the developer.notification
configuration:
If you want to take the full control over the notification sending, you can add this in one of your service providers:
Log pruning
Without pruning, the exception_logs
table can accumulate records very quickly. To mitigate this, you should schedule the dev:prune
Artisan command to run daily:
By default, all entries older than 24 hours will be pruned. You may use the hours option when calling the command to determine how long to retain Developer data. For example, the following command will delete all records created over 48 hours ago:
Profiling
As a developer sometimes you have to measure the memory usage or time consumed for such action. Laravel Developer helps you to do so:
Or:
And time measure:
Or:
Dev auth
Each api
has authentication, and testing it via HTTP Client (ie postman) we spend a lot of time to login users and copy the token, put in the next request and so on. Well now Laravel Developer provides an easy way to authenticate users in local
env using testing
token:
And send the request with the Authorization
header value testing
.
Note: Make sure the DevAuthMiddleware
is placed before the api
middleware.
Customize resolved user
By default, the first entry (usually user) from your config model app.providers.users.model
will be used, however, you can customize that.
In any of yours service providers, or in the same place you inject the DevAuthMiddleware
you can provide a callback which resolves the user instance:
Changing Bearer
If you're using laravel sanctum, and want to explicitely use / generate a Bearer for the resolved user, you can use the \Binarcode\LaravelDeveloper\Middleware\DevAuthMiddleware::class
instead, which follow the same syntax as the DevAuthMiddleware
.
Tests macros
dumpWithoutTrace
If you're annoying to always scroll up to message in your test when ->dump()
the response, you can use ->dumpWithoutTrace()
instead, it will return you back everything except the long array of trace.
Proxies
Often we're using common Collection
or EnumeratesValues
chain methods, but we cannot use those in other context.
when
when
is one of the most useful methods, let's assume we have this class:
And you want to set the order for the class, and item unless it exists. The usual way to do so is:
Using the when
chain method, this code become fluent:
To make it work, simply add the Binarcode\LaravelDeveloper\Concerns\Proxies
trait:
Store logs
Sometimes you may want to store simple logs (for instance when you send some API requests from your app, you may want to store the payload):
Now you will have an entry in your database table with the payload and the associated name.
Attach target
You can attach a target to your log, so it will relate to a model like this:
Or if you need to attach many models, use:
Attach meta
You also can attach meta data to your logs:
Telescope support
Package will automaticaly store exceptions into telescope.
Simply install telescope and mark the developer.telescope
on true
.
Telescope exceptions will be automatically stored on each slack($e)->persist()
call, or custom using the telescopeException($e, 'custom message')
helper.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Eduard Lupacescu
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-developer with dependencies
illuminate/contracts Version ^11.0
laravel/slack-notification-channel Version ^3.2
ext-json Version *