Skip to content

Commit

Permalink
Merge branch 'main' into 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
bezhanSalleh committed Nov 6, 2024
2 parents e83cf2e + cb72011 commit 6450b6b
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.6.0
uses: dependabot/fetch-metadata@v2.2.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
ref: ${{ github.head_ref }}

- name: Fix PHP code style issues
uses: aglipanci/laravel-pint-action@2.3.1
uses: aglipanci/laravel-pint-action@2.4

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.1]
laravel: [9.*]
laravel: [10.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 9.*
testbench: 7.*
- laravel: 10.*
testbench: 8.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand All @@ -44,4 +44,4 @@ jobs:
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/pest
run: vendor/bin/pest
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

All notable changes to `filament-exceptions` will be documented in this file.

## 2.1.0 - 2024-01-24

### What's Changed

* Adding isScopedToTenant at ExceptionResource by @LingMyat in https://github.com/bezhanSalleh/filament-exceptions/pull/47
* Add Custom Model Support & Fix Iterator Errors by @Fludem in https://github.com/bezhanSalleh/filament-exceptions/pull/46

### New Contributors

* @LingMyat made their first contribution in https://github.com/bezhanSalleh/filament-exceptions/pull/47
* @Fludem made their first contribution in https://github.com/bezhanSalleh/filament-exceptions/pull/46

**Full Changelog**: https://github.com/bezhanSalleh/filament-exceptions/compare/2.0.2...2.1.0

## 2.0.2 - 2024-01-09

### What's Changed
Expand Down
39 changes: 35 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,42 @@ class Handler extends ExceptionHandler

## Configuration
The configuration file filament-exceptions.php is automatically published into your config directory.
You can change icons and navigations settings as well as the active pill and slug there.

* **Mass Pruning**: By default exceptions older than a week are scheduled to be pruned daily. You can change the `period` by providing a date in the config or using carbon.
> **Note**
> in order for the schedule to work you need to make sure that you have configured your server if not follow this link on how to configure it. [Running The Scheduler](https://laravel.com/docs/9.x/scheduling#running-the-scheduler)
The config file provides you with multiple options to customize the plugin.

### Mass Pruning
By default Filament Exceptions is configured to prune exceptions older than 1 week.

To modify how long you'd like to store records for you can supply a Carbon object like so

```php
'period' => now()->subWeek(), // 1 week
'period' => now()->subDay(), // 1 day
'period' => now()->subDays(3), // 3 days
```
> **Note** This requires laravel scheduler to be setup and configured in order to work. You can see how to do that here [Running The Scheduler](https://laravel.com/docs/10.x/scheduling#running-the-scheduler)
### Custom Exception Model
For those who need to change the model this is possible using the configuration file.

```php
'exception_model' => Exception::class,
```

When creating your new exception model you should extend the default model

```php
<?php

namespace App\Models;

use BezhanSalleh\FilamentExceptions\Models\Exception as BaseException;

class Exception extends BaseException
{

}
```

## Theme
By default the plugin uses the default theme of Filamentphp, but if you are using a custom theme then include the plugins view path into the content array of your tailwind.config.js file:
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Orchestra\Testbench\Concerns\CreatesApplication;
use Orchestra\Testbench\Foundation\Application;

$basePathLocator = new class()
$basePathLocator = new class
{
use CreatesApplication;
};
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^7.0",
"nunomaduro/larastan": "^2.0",
"larastan/larastan": "^2.0",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^2.9",
"phpunit/phpunit": "^10.0",
Expand Down
43 changes: 25 additions & 18 deletions config/filament-exceptions.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php

use BezhanSalleh\FilamentExceptions\Models\Exception;

return [

'exception_model' => Exception::class,

'slug' => 'exceptions',

/** Show or hide in navigation/sidebar */
Expand All @@ -13,6 +17,9 @@
/** Whether to show a navigation badge. No effect, if navigation_enabled it set to false. */
'navigation_badge' => true,

/** Whether to scope exceptions to tenant */
'is_scoped_to_tenant' => true,

/** Icons to use for navigation (if enabled) and pills */
'icons' => [
'navigation' => 'heroicon-o-cpu-chip',
Expand All @@ -26,27 +33,27 @@
'is_globally_searchable' => false,

/**-------------------------------------------------
* Change the default active tab
*
* Exception => 1 (Default)
* Headers => 2
* Cookies => 3
* Body => 4
* Queries => 5
*/
* Change the default active tab
*
* Exception => 1 (Default)
* Headers => 2
* Cookies => 3
* Body => 4
* Queries => 5
*/
'active_tab' => 5,

/**-------------------------------------------------
* Here you can define when the exceptions should be pruned
* The default is 7 days (a week)
* The format for providing period should follow carbon's format. i.e.
* 1 day => 'subDay()',
* 3 days => 'subDays(3)',
* 7 days => 'subWeek()',
* 1 month => 'subMonth()',
* 2 months => 'subMonths(2)',
*
*/
* Here you can define when the exceptions should be pruned
* The default is 7 days (a week)
* The format for providing period should follow carbon's format. i.e.
* 1 day => 'subDay()',
* 3 days => 'subDays(3)',
* 7 days => 'subWeek()',
* 1 month => 'subMonth()',
* 2 months => 'subMonths(2)',
*
*/

'period' => now()->subWeek(),
];
31 changes: 31 additions & 0 deletions resources/lang/sk/filament-exceptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

return [

'labels' => [
'model' => 'Výnimka',
'model_plural' => 'Výnimky',
'navigation' => 'Výnimka',
'navigation_group' => 'Nastavenia',

'tabs' => [
'exception' => 'Výnimka',
'headers' => 'Hlavičky',
'cookies' => 'Cookies',
'body' => 'Telo',
'queries' => 'Dotazy',
],
],

'empty_list' => 'Hurá! len si sadnite a užívajte si 😎',

'columns' => [
'method' => 'Metóda',
'path' => 'Cesta',
'type' => 'Typ',
'code' => 'Kód',
'ip' => 'IP',
'occurred_at' => 'Nastalo o',
],

];
2 changes: 1 addition & 1 deletion resources/views/components/query-preview.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class="flex items-center px-2 py-1 text-xs font-medium transition duration-75 ro
class="w-full overflow-hidden rounded-lg bg-gray-50 dark:bg-gray-900 dark:border dark:border-gray-800">
@foreach ($query['bindings'] as $key => $value)
<div class="flex px-4 py-2">
<div class="py-2 font-mono text-gray-500 basis-1/12 dark:text-gray-400">{{ $key + 1 }}
<div class="py-2 font-mono text-gray-500 basis-1/12 dark:text-gray-400">{{ intVal($key) + 1 }}
</div>
<div
class="px-4 py-2 font-medium text-gray-500 rounded-lg basis-11/12 dark:text-gray-200 bg-gray-950/5 dark:bg-white/5">
Expand Down
6 changes: 6 additions & 0 deletions src/Facades/FilamentExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
use Illuminate\Support\Facades\Facade;

/**
* @method static void report(\Throwable $exception)
* @method static string getModel()
* @method static void reportException(\Throwable $exception)
* @method static array stringify(void $data)
* @method static bool store(array $data)
*
* @see \BezhanSalleh\FilamentExceptions\FilamentExceptions
*/
class FilamentExceptions extends Facade
Expand Down
58 changes: 16 additions & 42 deletions src/FilamentExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,38 @@

namespace BezhanSalleh\FilamentExceptions;

use BezhanSalleh\FilamentExceptions\Models\Exception;
use Illuminate\Foundation\Application;
use BezhanSalleh\FilamentExceptions\Models\Exception as ExceptionModel;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
use Spatie\LaravelIgnition\Recorders\QueryRecorder\QueryRecorder;
use Throwable;

class FilamentExceptions
{
/**
* @var Request
*/
protected $request;

protected Application $app;
public function __construct(
protected Request $request
) {}

/**
* Reporter constructor.
* @throws BindingResolutionException
*/
public function __construct(Request $request)
{
$this->request = $request;
}

/**
* @return void
*/
public static function report(Throwable $exception)
public static function report(Throwable $exception): void
{
$reporter = new static(request());

$reporter->reportException($exception);
}

public static function getModel(): string
{
return config('filament-exceptions.exception_model') ?? ExceptionModel::class;
}

/**
* @return void
* @throws BindingResolutionException
*/
public function reportException(Throwable $exception)
public function reportException(Throwable $exception): void
{
$data = [
'method' => request()->getMethod(),
Expand All @@ -61,43 +54,24 @@ public function reportException(Throwable $exception)

$data = $this->stringify($data);

try {
$this->store($data);
} catch (Throwable $e) {
throw $e;
}
$this->store($data);
}

/**
* Convert all items to string.
*/
public function stringify($data): array
{
return array_map(function ($item) {
return is_array($item) ? json_encode($item, JSON_OBJECT_AS_ARRAY) : (string) $item;
}, $data);
}

/**
* Store exception info to db.
*/
public function store(array $data): bool
{
try {
Exception::query()->create($data);
static::getModel()::create($data);

return true;
} catch (Throwable $e) {
return false;
}
}

public static function formatFileName(string $fileName): string
{
return str($fileName)
->after(str(request()->getHost())->beforeLast('.')->toString())
->afterLast('/')
->prepend('.../')
->toString();
}
}
14 changes: 11 additions & 3 deletions src/Resources/ExceptionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace BezhanSalleh\FilamentExceptions\Resources;

use BezhanSalleh\FilamentExceptions\Models\Exception;
use BezhanSalleh\FilamentExceptions\Facades\FilamentExceptions;
use BezhanSalleh\FilamentExceptions\Resources\ExceptionResource\Pages;
use Filament\Forms;
use Filament\Forms\Form;
Expand All @@ -12,7 +12,10 @@

class ExceptionResource extends Resource
{
protected static ?string $model = Exception::class;
public static function getModel(): string
{
return FilamentExceptions::getModel();
}

public static function getModelLabel(): string
{
Expand Down Expand Up @@ -47,7 +50,7 @@ public static function getSlug(): string
public static function getNavigationBadge(): ?string
{
if (config('filament-exceptions.navigation_badge')) {
return static::$model::count();
return static::getEloquentQuery()->count();
}

return null;
Expand All @@ -63,6 +66,11 @@ public static function getNavigationSort(): ?int
return config('filament-exceptions.navigation_sort');
}

public static function isScopedToTenant(): bool
{
return config('filament-exceptions.is_scoped_to_tenant', true);
}

public static function canGloballySearch(): bool
{
return config('filament-exceptions.is_globally_searchable')
Expand Down
Loading

0 comments on commit 6450b6b

Please sign in to comment.