-
Notifications
You must be signed in to change notification settings - Fork 56
Open
Description
Hi, I need a help, am getting this error:
In app.php line 34:
Call to undefined function App\Common\Core\Support\shouldRespondWithJson()
and in composer.json
"autoload": {
"files": [
"app/Common/Core/Support/functions.php"
],
},
app/Common/Core/Support/functions.php
looks like:
<?php
namespace App\Common\Core\Support;
use Throwable;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
if (!function_exists('App\Common\Core\Support\shouldRespondWithJson')) {
/**
* Determine if the exception should be rendered as JSON.
*
* In production, always return JSON.
* In non-production, return JSON unless the developer explicitly disables it
* via the `disable-json` query parameter.
*
* @param \Illuminate\Http\Request $request
* @param \Throwable $e
* @return bool
*/
function shouldRespondWithJson(Request $request, Throwable $e): bool
{
$isProduction = app()->isProduction();
$forceJson = $isProduction || !$request->boolean('disable-json', false);
if (!$isProduction)
Log::debug('Exception rendering as ' . ($forceJson ? 'JSON' : 'HTML'), [
'url' => $request->fullUrl(),
'exception' => get_class($e),
]);
/* Always return JSON in production, or if the developer did not explicitly disable it.
In non-production, use the default logic to determine if the request expects JSON. */
return $forceJson || $request->expectsJson();
}
}
And then am calling it in bootstrap/app.php
like:
use function App\Common\Core\Support\shouldRespondWithJson;
return Application::configure(basePath: dirname(__DIR__))
...
->withExceptions(function (Exceptions $exceptions): void {
$exceptions->shouldRenderJsonWhen(shouldRespondWithJson(...));
})
->create();
Is there any way I can tell Laravel Extra
where to find this function?
thx for any advice
Metadata
Metadata
Assignees
Labels
No labels