Skip to content

Commit f915dea

Browse files
authored
Merge pull request #5212 from Laravel-Backpack/better-debug-error-message-for-backpack-view-function
Better debug error message for backpack_view() function
2 parents c5b6fe8 + 36443d3 commit f915dea

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/helpers.php

Lines changed: 17 additions & 1 deletion
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,7 +257,22 @@ function backpack_view($view)
256257
}
257258
}
258259

259-
dd('Could not find Backpack view ['.$view.'] in theme namespace, fallback namespace nor UI namespace.');
260+
$errorMessage = 'The view: ['.$view.'] was not found in any of the following view paths: ['.implode(' ], [ ', $viewPaths).']';
261+
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';
271+
272+
return '- Called in: '.Str::after($functionFile, base_path()).' on line: '.$functionLine;
273+
})();
274+
275+
abort(500, $errorMessage.$errorDetails);
260276
}
261277
}
262278

0 commit comments

Comments
 (0)