Skip to content

Commit f6cf945

Browse files
authored
Merge pull request #18 from wamilomarov/master
Laravel 8 compatibility
2 parents 32c97a3 + 4ce575d commit f6cf945

File tree

6 files changed

+53
-47
lines changed

6 files changed

+53
-47
lines changed

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
],
1414
"require": {
1515
"php": ">=7.0.0",
16-
"laravel/framework": "~5.5",
17-
"encore/laravel-admin": "~1.5"
16+
"laravel/framework": ">=5.5",
17+
"encore/laravel-admin": ">=1.5",
18+
"ext-json": "*"
1819
},
1920
"require-dev": {
20-
"phpunit/phpunit": "~6.0",
21-
"laravel/laravel": "~5.5"
21+
"phpunit/phpunit": ">=6.0",
22+
"laravel/laravel": ">=5.5"
2223
},
2324
"autoload": {
2425
"psr-4": {

database/migrations/2017_07_17_040159_create_exceptions_table.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ public function up()
4343

4444
Schema::connection($connection)->create($table, function (Blueprint $table) {
4545
$table->increments('id');
46-
$table->string('type');
46+
$table->string('type', 255);
4747
$table->string('code');
48-
$table->string('message');
49-
$table->string('file');
48+
$table->string('message', 255);
49+
$table->string('file', 255);
5050
$table->integer('line');
5151
$table->text('trace');
5252
$table->string('method');
53-
$table->string('path');
53+
$table->string('path', 255);
5454
$table->text('query');
5555
$table->text('body');
5656
$table->text('cookies');

src/BootExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Encore\Admin\Reporter;
44

55
use Encore\Admin\Admin;
6+
use Illuminate\Routing\Router;
67

78
trait BootExtension
89
{
@@ -23,7 +24,7 @@ public static function boot()
2324
protected static function registerRoutes()
2425
{
2526
parent::routes(function ($router) {
26-
/* @var \Illuminate\Routing\Router $router */
27+
/* @var Router $router */
2728
$router->resource('exceptions', 'Encore\Admin\Reporter\ExceptionController');
2829
});
2930
}

src/ExceptionController.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Encore\Admin\Grid;
88
use Encore\Admin\Layout\Content;
99
use Encore\Admin\Reporter\Tracer\Parser;
10+
use Illuminate\Http\JsonResponse;
1011

1112
class ExceptionController
1213
{
@@ -17,7 +18,7 @@ class ExceptionController
1718
*
1819
* @return Content
1920
*/
20-
public function index()
21+
public function index(): Content
2122
{
2223
return Admin::content(function (Content $content) {
2324
$content->header('Exception');
@@ -27,7 +28,7 @@ public function index()
2728
});
2829
}
2930

30-
public function grid()
31+
public function grid(): Grid
3132
{
3233
return Admin::grid(ExceptionModel::class, function (Grid $grid) {
3334
$grid->model()->orderBy('id', 'desc');
@@ -76,7 +77,7 @@ public function grid()
7677
$filter->disableIdFilter();
7778
$filter->like('type');
7879
$filter->like('message');
79-
$filter->between("created_at")->datetime();
80+
$filter->between('created_at')->datetime();
8081
});
8182

8283
$grid->disableCreation();
@@ -112,11 +113,11 @@ public function show($id)
112113
});
113114
}
114115

115-
public function destroy($id)
116+
public function destroy($id): JsonResponse
116117
{
117118
$ids = explode(',', $id);
118119

119-
if (ExceptionModel::whereIn('id', $ids)->delete()) {
120+
if (ExceptionModel::query()->whereIn('id', $ids)->delete()) {
120121
return response()->json([
121122
'status' => true,
122123
'message' => trans('admin.delete_succeeded'),

src/ExceptionModel.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ class ExceptionModel extends Model
1515
'OPTIONS' => 'grey',
1616
];
1717

18+
protected $fillable = [
19+
'type',
20+
'code',
21+
'message',
22+
'file',
23+
'line',
24+
'trace',
25+
'method',
26+
'path',
27+
'query',
28+
'body',
29+
'cookies',
30+
'headers',
31+
'ip',
32+
];
33+
1834
/**
1935
* Settings constructor.
2036
*

src/Reporter.php

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Encore\Admin\Extension;
66
use Illuminate\Http\Request;
7+
use Illuminate\Support\Arr;
8+
use Throwable;
79

810
class Reporter extends Extension
911
{
@@ -25,37 +27,37 @@ public function __construct(Request $request)
2527
}
2628

2729
/**
28-
* @param \Exception $exception
30+
* @param Throwable $exception
2931
*
30-
* @return mixed
32+
* @return void
3133
*/
32-
public static function report(\Exception $exception)
34+
public static function report(Throwable $exception)
3335
{
3436
$reporter = new static(request());
3537

36-
return $reporter->reportException($exception);
38+
$reporter->reportException($exception);
3739
}
3840

3941
/**
40-
* @param \Exception $exception
42+
* @param Throwable $exception
4143
*
42-
* @return bool
44+
* @return void
4345
*/
44-
public function reportException(\Exception $exception)
46+
public function reportException(Throwable $exception)
4547
{
4648
$data = [
4749

4850
// Request info.
4951
'method' => $this->request->getMethod(),
5052
'ip' => $this->request->getClientIps(),
5153
'path' => $this->request->path(),
52-
'query' => array_except($this->request->all(), ['_pjax', '_token', '_method', '_previous_']),
54+
'query' => Arr::except($this->request->all(), ['_pjax', '_token', '_method', '_previous_']),
5355
'body' => $this->request->getContent(),
5456
'cookies' => $this->request->cookies->all(),
55-
'headers' => array_except($this->request->headers->all(), 'cookie'),
57+
'headers' => Arr::except($this->request->headers->all(), 'cookie'),
5658

5759
// Exception info.
58-
'exception' => get_class($exception),
60+
'type' => get_class($exception),
5961
'code' => $exception->getCode(),
6062
'file' => $exception->getFile(),
6163
'line' => $exception->getLine(),
@@ -67,7 +69,7 @@ public function reportException(\Exception $exception)
6769

6870
try {
6971
$this->store($data);
70-
} catch (\Exception $e) {
72+
} catch (Throwable $e) {
7173
// $result = $this->reportException($e);
7274
}
7375

@@ -81,7 +83,7 @@ public function reportException(\Exception $exception)
8183
*
8284
* @return array
8385
*/
84-
public function stringify($data)
86+
public function stringify($data): array
8587
{
8688
return array_map(function ($item) {
8789
return is_array($item) ? json_encode($item, JSON_OBJECT_AS_ARRAY) : (string) $item;
@@ -95,30 +97,15 @@ public function stringify($data)
9597
*
9698
* @return bool
9799
*/
98-
public function store(array $data)
100+
public function store(array $data): bool
99101
{
100-
$exception = new ExceptionModel();
101-
102-
$exception->type = $data['exception'];
103-
$exception->code = $data['code'];
104-
$exception->message = $data['message'];
105-
$exception->file = $data['file'];
106-
$exception->line = $data['line'];
107-
$exception->trace = $data['trace'];
108-
$exception->method = $data['method'];
109-
$exception->path = $data['path'];
110-
$exception->query = $data['query'];
111-
$exception->body = $data['body'];
112-
$exception->cookies = $data['cookies'];
113-
$exception->headers = $data['headers'];
114-
$exception->ip = $data['ip'];
115-
116102
try {
117-
$exception->save();
118-
} catch (\Exception $e) {
103+
ExceptionModel::query()->create($data);
104+
105+
return true;
106+
} catch (Throwable $e) {
107+
return false;
119108
//dd($e);
120109
}
121-
122-
return $exception->save();
123110
}
124111
}

0 commit comments

Comments
 (0)