Skip to content

Commit 6450b6b

Browse files
committed
Merge branch 'main' into 2.x
2 parents e83cf2e + cb72011 commit 6450b6b

File tree

15 files changed

+156
-82
lines changed

15 files changed

+156
-82
lines changed

.github/workflows/dependabot-auto-merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
- name: Dependabot metadata
1515
id: metadata
16-
uses: dependabot/fetch-metadata@v1.6.0
16+
uses: dependabot/fetch-metadata@v2.2.0
1717
with:
1818
github-token: "${{ secrets.GITHUB_TOKEN }}"
1919

.github/workflows/fix-php-code-style-issues.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
ref: ${{ github.head_ref }}
1414

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

1818
- name: Commit changes
1919
uses: stefanzweifel/git-auto-commit-action@v5

.github/workflows/run-tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ jobs:
1414
matrix:
1515
os: [ubuntu-latest, windows-latest]
1616
php: [8.1]
17-
laravel: [9.*]
17+
laravel: [10.*]
1818
stability: [prefer-lowest, prefer-stable]
1919
include:
20-
- laravel: 9.*
21-
testbench: 7.*
20+
- laravel: 10.*
21+
testbench: 8.*
2222

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

@@ -44,4 +44,4 @@ jobs:
4444
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
4545
4646
- name: Execute tests
47-
run: vendor/bin/pest
47+
run: vendor/bin/pest

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

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

5+
## 2.1.0 - 2024-01-24
6+
7+
### What's Changed
8+
9+
* Adding isScopedToTenant at ExceptionResource by @LingMyat in https://github.com/bezhanSalleh/filament-exceptions/pull/47
10+
* Add Custom Model Support & Fix Iterator Errors by @Fludem in https://github.com/bezhanSalleh/filament-exceptions/pull/46
11+
12+
### New Contributors
13+
14+
* @LingMyat made their first contribution in https://github.com/bezhanSalleh/filament-exceptions/pull/47
15+
* @Fludem made their first contribution in https://github.com/bezhanSalleh/filament-exceptions/pull/46
16+
17+
**Full Changelog**: https://github.com/bezhanSalleh/filament-exceptions/compare/2.0.2...2.1.0
18+
519
## 2.0.2 - 2024-01-09
620

721
### What's Changed

README.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,42 @@ class Handler extends ExceptionHandler
7878

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

83-
* **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.
84-
> **Note**
85-
> 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)
82+
The config file provides you with multiple options to customize the plugin.
83+
84+
### Mass Pruning
85+
By default Filament Exceptions is configured to prune exceptions older than 1 week.
86+
87+
To modify how long you'd like to store records for you can supply a Carbon object like so
88+
89+
```php
90+
'period' => now()->subWeek(), // 1 week
91+
'period' => now()->subDay(), // 1 day
92+
'period' => now()->subDays(3), // 3 days
93+
```
94+
> **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)
95+
96+
### Custom Exception Model
97+
For those who need to change the model this is possible using the configuration file.
98+
99+
```php
100+
'exception_model' => Exception::class,
101+
```
102+
103+
When creating your new exception model you should extend the default model
104+
105+
```php
106+
<?php
107+
108+
namespace App\Models;
109+
110+
use BezhanSalleh\FilamentExceptions\Models\Exception as BaseException;
111+
112+
class Exception extends BaseException
113+
{
114+
115+
}
116+
```
86117

87118
## Theme
88119
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:

bootstrap/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Orchestra\Testbench\Concerns\CreatesApplication;
77
use Orchestra\Testbench\Foundation\Application;
88

9-
$basePathLocator = new class()
9+
$basePathLocator = new class
1010
{
1111
use CreatesApplication;
1212
};

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"require-dev": {
2626
"laravel/pint": "^1.0",
2727
"nunomaduro/collision": "^7.0",
28-
"nunomaduro/larastan": "^2.0",
28+
"larastan/larastan": "^2.0",
2929
"orchestra/testbench": "^8.0",
3030
"pestphp/pest": "^2.9",
3131
"phpunit/phpunit": "^10.0",

config/filament-exceptions.php

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?php
22

3+
use BezhanSalleh\FilamentExceptions\Models\Exception;
4+
35
return [
46

7+
'exception_model' => Exception::class,
8+
59
'slug' => 'exceptions',
610

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

20+
/** Whether to scope exceptions to tenant */
21+
'is_scoped_to_tenant' => true,
22+
1623
/** Icons to use for navigation (if enabled) and pills */
1724
'icons' => [
1825
'navigation' => 'heroicon-o-cpu-chip',
@@ -26,27 +33,27 @@
2633
'is_globally_searchable' => false,
2734

2835
/**-------------------------------------------------
29-
* Change the default active tab
30-
*
31-
* Exception => 1 (Default)
32-
* Headers => 2
33-
* Cookies => 3
34-
* Body => 4
35-
* Queries => 5
36-
*/
36+
* Change the default active tab
37+
*
38+
* Exception => 1 (Default)
39+
* Headers => 2
40+
* Cookies => 3
41+
* Body => 4
42+
* Queries => 5
43+
*/
3744
'active_tab' => 5,
3845

3946
/**-------------------------------------------------
40-
* Here you can define when the exceptions should be pruned
41-
* The default is 7 days (a week)
42-
* The format for providing period should follow carbon's format. i.e.
43-
* 1 day => 'subDay()',
44-
* 3 days => 'subDays(3)',
45-
* 7 days => 'subWeek()',
46-
* 1 month => 'subMonth()',
47-
* 2 months => 'subMonths(2)',
48-
*
49-
*/
47+
* Here you can define when the exceptions should be pruned
48+
* The default is 7 days (a week)
49+
* The format for providing period should follow carbon's format. i.e.
50+
* 1 day => 'subDay()',
51+
* 3 days => 'subDays(3)',
52+
* 7 days => 'subWeek()',
53+
* 1 month => 'subMonth()',
54+
* 2 months => 'subMonths(2)',
55+
*
56+
*/
5057

5158
'period' => now()->subWeek(),
5259
];
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
return [
4+
5+
'labels' => [
6+
'model' => 'Výnimka',
7+
'model_plural' => 'Výnimky',
8+
'navigation' => 'Výnimka',
9+
'navigation_group' => 'Nastavenia',
10+
11+
'tabs' => [
12+
'exception' => 'Výnimka',
13+
'headers' => 'Hlavičky',
14+
'cookies' => 'Cookies',
15+
'body' => 'Telo',
16+
'queries' => 'Dotazy',
17+
],
18+
],
19+
20+
'empty_list' => 'Hurá! len si sadnite a užívajte si 😎',
21+
22+
'columns' => [
23+
'method' => 'Metóda',
24+
'path' => 'Cesta',
25+
'type' => 'Typ',
26+
'code' => 'Kód',
27+
'ip' => 'IP',
28+
'occurred_at' => 'Nastalo o',
29+
],
30+
31+
];

resources/views/components/query-preview.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class="flex items-center px-2 py-1 text-xs font-medium transition duration-75 ro
3434
class="w-full overflow-hidden rounded-lg bg-gray-50 dark:bg-gray-900 dark:border dark:border-gray-800">
3535
@foreach ($query['bindings'] as $key => $value)
3636
<div class="flex px-4 py-2">
37-
<div class="py-2 font-mono text-gray-500 basis-1/12 dark:text-gray-400">{{ $key + 1 }}
37+
<div class="py-2 font-mono text-gray-500 basis-1/12 dark:text-gray-400">{{ intVal($key) + 1 }}
3838
</div>
3939
<div
4040
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">

src/Facades/FilamentExceptions.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
use Illuminate\Support\Facades\Facade;
66

77
/**
8+
* @method static void report(\Throwable $exception)
9+
* @method static string getModel()
10+
* @method static void reportException(\Throwable $exception)
11+
* @method static array stringify(void $data)
12+
* @method static bool store(array $data)
13+
*
814
* @see \BezhanSalleh\FilamentExceptions\FilamentExceptions
915
*/
1016
class FilamentExceptions extends Facade

src/FilamentExceptions.php

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,38 @@
22

33
namespace BezhanSalleh\FilamentExceptions;
44

5-
use BezhanSalleh\FilamentExceptions\Models\Exception;
6-
use Illuminate\Foundation\Application;
5+
use BezhanSalleh\FilamentExceptions\Models\Exception as ExceptionModel;
6+
use Illuminate\Contracts\Container\BindingResolutionException;
77
use Illuminate\Http\Request;
88
use Illuminate\Support\Arr;
9-
use Illuminate\Support\Facades\DB;
109
use Spatie\LaravelIgnition\Recorders\QueryRecorder\QueryRecorder;
1110
use Throwable;
1211

1312
class FilamentExceptions
1413
{
15-
/**
16-
* @var Request
17-
*/
18-
protected $request;
19-
20-
protected Application $app;
14+
public function __construct(
15+
protected Request $request
16+
) {}
2117

2218
/**
23-
* Reporter constructor.
19+
* @throws BindingResolutionException
2420
*/
25-
public function __construct(Request $request)
26-
{
27-
$this->request = $request;
28-
}
29-
30-
/**
31-
* @return void
32-
*/
33-
public static function report(Throwable $exception)
21+
public static function report(Throwable $exception): void
3422
{
3523
$reporter = new static(request());
3624

3725
$reporter->reportException($exception);
3826
}
3927

28+
public static function getModel(): string
29+
{
30+
return config('filament-exceptions.exception_model') ?? ExceptionModel::class;
31+
}
32+
4033
/**
41-
* @return void
34+
* @throws BindingResolutionException
4235
*/
43-
public function reportException(Throwable $exception)
36+
public function reportException(Throwable $exception): void
4437
{
4538
$data = [
4639
'method' => request()->getMethod(),
@@ -61,43 +54,24 @@ public function reportException(Throwable $exception)
6154

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

64-
try {
65-
$this->store($data);
66-
} catch (Throwable $e) {
67-
throw $e;
68-
}
57+
$this->store($data);
6958
}
7059

71-
/**
72-
* Convert all items to string.
73-
*/
7460
public function stringify($data): array
7561
{
7662
return array_map(function ($item) {
7763
return is_array($item) ? json_encode($item, JSON_OBJECT_AS_ARRAY) : (string) $item;
7864
}, $data);
7965
}
8066

81-
/**
82-
* Store exception info to db.
83-
*/
8467
public function store(array $data): bool
8568
{
8669
try {
87-
Exception::query()->create($data);
70+
static::getModel()::create($data);
8871

8972
return true;
9073
} catch (Throwable $e) {
9174
return false;
9275
}
9376
}
94-
95-
public static function formatFileName(string $fileName): string
96-
{
97-
return str($fileName)
98-
->after(str(request()->getHost())->beforeLast('.')->toString())
99-
->afterLast('/')
100-
->prepend('.../')
101-
->toString();
102-
}
10377
}

src/Resources/ExceptionResource.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace BezhanSalleh\FilamentExceptions\Resources;
44

5-
use BezhanSalleh\FilamentExceptions\Models\Exception;
5+
use BezhanSalleh\FilamentExceptions\Facades\FilamentExceptions;
66
use BezhanSalleh\FilamentExceptions\Resources\ExceptionResource\Pages;
77
use Filament\Forms;
88
use Filament\Forms\Form;
@@ -12,7 +12,10 @@
1212

1313
class ExceptionResource extends Resource
1414
{
15-
protected static ?string $model = Exception::class;
15+
public static function getModel(): string
16+
{
17+
return FilamentExceptions::getModel();
18+
}
1619

1720
public static function getModelLabel(): string
1821
{
@@ -47,7 +50,7 @@ public static function getSlug(): string
4750
public static function getNavigationBadge(): ?string
4851
{
4952
if (config('filament-exceptions.navigation_badge')) {
50-
return static::$model::count();
53+
return static::getEloquentQuery()->count();
5154
}
5255

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

69+
public static function isScopedToTenant(): bool
70+
{
71+
return config('filament-exceptions.is_scoped_to_tenant', true);
72+
}
73+
6674
public static function canGloballySearch(): bool
6775
{
6876
return config('filament-exceptions.is_globally_searchable')

0 commit comments

Comments
 (0)