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

garylogan's avatar

Please help

I am new to this and need some help please. I am installing an app on a site but have got a load of errors. Is it ok if I post a link? Thanks

1 like
34 replies
garylogan's avatar

App\Http\Middleware\DemoModeMiddleware::handle(): Return value must be of type Symfony\Component\HttpFoundation\Response, none returned is the error. Thank you

Jsanwo64's avatar

SHow what you have in your middleware where the error is coming from and also the code that trigeers the error itself

tykus's avatar

You can post your code; simply wrap your copy/pasted code snippet inside triple backticks, e.g.

```
// your code
```

You need to ensure that the Middleware returns a Response, or eventually delegate to the next Middleware in the stack:

return $next($request);
garylogan's avatar
garylogan's avatar

This is the new error

ParseError Unmatched '}' app/Http/Middleware/DemoModeMiddleware.php :117 ], 403); }

    return redirect()->back()->with('error', $message);
}

} } }

tykus's avatar

You are not returning:

    public function handle(Request $request, Closure $next): Response
    {
        if (!config('app.is_demo', false)) {
            return $next($request);  // return!
        }

        // Allow GET requests (viewing data)
        if ($request->isMethod('GET')) {
            return $next($request); // return!
        }

        // Allow POST requests for creating new data
        if ($request->isMethod('POST') && !$this->isUpdateOrDeleteRoute($request)) {
            return $next($request);
        }

        // Block PUT, PATCH, DELETE requests (editing/deleting existing data)
        if (in_array($request->method(), ['PUT', 'PATCH', 'DELETE'])) {
            return $this->demoModeResponse($request);
        }

        // Block specific update/delete POST routes
        if ($this->isUpdateOrDeleteRoute($request)) {
            return $this->demoModeResponse($request);
        }

        return $next($request); // return!
    }
tykus's avatar

This is the new error

ParseError Unmatched '}' app/Http/Middleware/DemoModeMiddleware.php :117 ], 403); }

This is simply a mismatching brace { - if you use a decent IDE it should complain about it and be easily fixed

garylogan's avatar

Thank you. One error after another

ParseError syntax error, unexpected token "public", expecting "{" app/Http/Middleware/DemoModeMiddleware.php :14 class DemoModeMiddleware

/**
 * Handle an incoming request.
 */
public function handle(Request $request, Closure $next): Response
{
    if (!config
tykus's avatar

Probably a missing semi-colon or brace.

Please paste the entire file here so we can see where the error is coming from.

garylogan's avatar

Thank you

tykus's avatar

You are missing a { after the classdeclaration; and a closing brace } at the end of the file

garylogan's avatar

Thanks

Now telling me

ParseError syntax error, unexpected token "function", expecting "{" app/Http/Middleware/DemoModeMiddleware.php :14 class DemoModeMiddleware

/**
 * Handle an incoming request.
 */
function handle(Request $request, Closure $next): Response
{
    if (!config('app.is_demo', false)) {
        return $next($request
tykus's avatar

You still are missing an opening brace {

Jsanwo64's avatar

Just as @tykus has stated you have the followng missing

  1. Class Declaration Missing Braces
  2. All methods in a class should explicitly define visibility (public, protected, or private) You have
function handle(Request $request, Closure $next): Response
  1. Unclosed handle() Method

Those i can see so far

Jsanwo64's avatar

Try this and let's see if you get an error

garylogan's avatar

ParseError Unclosed '{' app/Http/Middleware/DemoModeMiddleware.php :92

    return false;
}

public function demoModeResponse(Request $request): Response
{
Jsanwo64's avatar

For your code or the corrected code i suggested you try?

Jsanwo64's avatar

Try this

I saw where the error came from. My bad

garylogan's avatar

syntax error, unexpected token "}", expecting ";" or "{" app/Http/Middleware/DemoModeMiddleware.php :92

    return false;
}

public function demoModeResponse(Request $request): Response
} only create new data, not modify existing demo data.';

    if ($request->expectsJson() || $request->is('api/*')) {
        return
Jsanwo64's avatar

Replace the demoModeResponse function with

public function demoModeResponse(Request $request)
{
    $message = 'This action is disabled in demo mode. You can only create new data, not modify existing demo data.';

    if ($request->expectsJson() || $request->is('api/*')) {
        return response()->json([
            'message' => $message,
            'demo_mode' => true
        ], 403);
    }

    return redirect()->back()->with('error', $message);
}
Jsanwo64's avatar

Reason you got that error was because i omitted use of Symfony\Component\HttpFoundation\Response; import at the top

garylogan's avatar

Namespace declaration statement has to be the very first statement or after any declare call in the script app/Http/Middleware/DemoModeMiddleware.php :5

Jsanwo64's avatar

Can you paste the whole code you have? Let me check again and compare what you pasted as the code you had had errors with.

garylogan's avatar

Sure thing.

Jsanwo64's avatar

The code should work unless you are adding some sort of space before the namespace

this error you got

Namespace declaration statement has to be the very first statement or after any declare call in the script app/Http/Middleware/DemoModeMiddleware.php :5

means

This error means there's something before the <?php tag or between <?php and the namespace declaration.

garylogan's avatar

ParseError Unmatched '}' app/Http/Middleware/DemoModeMiddleware.php :105 }

return redirect()->back()->with('error', $message);

} }ck()->with('error', $message); } }"

Jsanwo64's avatar

The code i fixed is not up to 105 line.

do the following

# Clear all Laravel caches
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear

or just run

php artisan optimize:clear
garylogan's avatar

Sorry man no luck. It's just error after error. Thanks so much for your help though

1 like
JussiMannisto's avatar

You should use an IDE/editor that highlights syntax errors for you if you're not very familiar with PHP.

1 like
Snapey's avatar

you can install vscode and intelliphense or devsense plugins for free, and kill all these errors as you type them!

Please or to participate in this conversation.