Skip to content

Commit 75158ea

Browse files
committed
improve message
1 parent b99d2d0 commit 75158ea

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/helpers.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Backpack\Basset\Facades\Basset;
44
use Creativeorange\Gravatar\Facades\Gravatar;
55
use Illuminate\Support\Facades\Log;
6+
use Illuminate\Support\Str;
67

78
if (! function_exists('backpack_url')) {
89
/**
@@ -256,15 +257,23 @@ function backpack_view($view)
256257
}
257258
}
258259

259-
// we only run the back trace in case we couldn't find the view
260-
// and help developer understand where is the error
261-
$backtrace = env('APP_ENV') !== 'production' && env('APP_DEBUG') ? debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1) : [];
260+
$errorMessage = 'The view: ['.$view.'] was not found in any of the following view paths: ['.implode(' ], [ ', $viewPaths).']';
262261

263-
$functionCaller = $backtrace[0] ?? [];
264-
$functionLine = $functionCaller['line'] ?? 'N/A';
265-
$functionFile = $functionCaller['file'] ?? 'N/A';
262+
$errorDetails = (function() {
263+
if (env('APP_ENV') === 'production' || !env('APP_DEBUG')) {
264+
return '';
265+
}
266+
267+
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2) ?? [];
268+
$functionCaller = $backtrace[1] ?? [];
269+
$functionLine = $functionCaller['line'] ?? 'N/A';
270+
$functionFile = $functionCaller['file'] ?? 'N/A';
266271

267-
abort(500, 'The view: ['.$view.'] was not found in any of the following view paths: ['.implode(' ], [ ', $viewPaths).'] - called on: '.$functionFile.' on line: '.$functionLine);
272+
return '- Called in: '.Str::after($functionFile, base_path()).' on line: '.$functionLine;
273+
})();
274+
275+
276+
abort(500, $errorMessage.$errorDetails);
268277
}
269278
}
270279

0 commit comments

Comments
 (0)