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

BobbyAxe61's avatar

Double Response On RuntimeException No application encryption key

i received double responses when i remove my application key and ran the application, follow these steps to replicate the bug

    composer create-project laravel/laravel "project-name"
    cd project-name
    nano .env

Delete the application key if any has been set

    APP_KEY=

save the .env file go to the Handler.php file and add the following

    cd App\Exceptions
    nano Handler.php

Add the following to the render function

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $exception
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $exception)
    {
        // Thrown when an exception occurs.
        if ($exception instanceof Exception) {
            return response()->json('okay', 500);
        }

        return parent::render($request, $exception);
    }

Then run on your browser visit http://127.0.0.1:8000/ or http://serving_address/ You should receive two json response instead of one

My question, is this a bug? should i not return json response from the handler? how do i fix this?

0 likes
2 replies
walidabou's avatar

Why did you delete the APP_KEY. Laravel needs it for security reasons. Run php artisan key:generate to generate a new one.

BobbyAxe61's avatar

@walidabou all for science, i did it all for science :) actually the issue is not the missing key but the fact that the response is doubled which shouldn't be, also deleting the key was the quickest way to throw that specific runtime exception type.

1 like

Please or to participate in this conversation.