Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sameerast's avatar

Attempt to assign property 'debug' of non-object

I call to controller index using ajax,

Controller: public function index(Request $request) { if ($request->ajax()) {

        $client = Clients::with('support', 'domains', 'projects')
            ->find($request->client_id);

        return response()
            ->json([$client->domains, $client->projects], 200);
    }

    $domains = Domains::all();
    $domainsCount = $domains->count();

    return view('domains.index', [
        'domains' => $domains,
        'domainsCount' => $domainsCount
    ]);
}

{message: "Attempt to assign property 'debug' of non-object", exception: "ErrorException",} exception: "ErrorException" file: "/var/www/xxxx/vendor/lanin/laravel-api-debugger/src/Debugger.php" line: 118 message: "Attempt to assign property 'debug' of non-object" trace: [{file: "/var/www/xxx/vendor/lanin/laravel-api-debugger/src/Debugger.php", line: 118,},] 0: {file: "/var/www/xxx/vendor/lanin/laravel-api-debugger/src/Debugger.php", line: 118,} class: "Illuminate\Foundation\Bootstrap\HandleExceptions" file: "/var/www/xxx/vendor/lanin/laravel-api-debugger/src/Debugger.php" function: "handleError" line: 118 type: "->" 1: {file: "/var/www/xxx/vendor/lanin/laravel-api-debugger/src/Debugger.php", line: 43,} class: "Lanin\Laravel\ApiDebugger\Debugger" file: "/var/www/xxx/vendor/lanin/laravel-api-debugger/src/Debugger.php" function: "updateResponse" line: 43 type: "->" 2: {file: "/var/www/xxx/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php", line: 360,} class: "Lanin\Laravel\ApiDebugger\Debugger" file: "/var/www/xxx/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php" function: "Lanin\Laravel\ApiDebugger{closure}" line: 360 type: "->" 3: {file: "/var/www/xxx/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php", line: 209,} class: "Illuminate\Events\Dispatcher" file: "/var/www/xxx/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php" function: "Illuminate\Events{closure}" line: 209 type: "->" 4: {file: "/var/www/xxx/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", line: 128,} class: "Illuminate\Events\Dispatcher" file: "/var/www/xxx/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php" function: "dispatch" line: 128 type: "->" 5: {file: "/var/www/xxx/public/index.php", line: 55, function: "handle",} class: "Illuminate\Foundation\Http\Kernel" file: "/var/www/xxx/public/index.php" function: "handle" line: 55 type: "->"

Console error: GET http://domain.com/domains?client_id=1 500 (Internal Server Error)

What is the mistake I have done?

0 likes
2 replies
bobbybouwmann's avatar
Level 88

It seems that the error comes from the mlanin/laravel-api-debugger package. Have you tried removing or disabling it to check if your controller works correctly?

Also your response in your ajax call should be key value based. So someting like this

return response()->json([
    'domains' => $client->domains,
    'projects' => $client->projects,
], 200);

It could be that this already throws an error and that the laravel-api-debugger can't handle that error and throws an error as well :P

2 likes
Sameerast's avatar

Thanks, key, and value added. works fine.

Please or to participate in this conversation.