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

devondahon's avatar

syntax error, unexpected token "try"

My email verification controller doesn't work anymore since my last manual (minor) upgrade of Laravel ("laravel/framework": "^8.12").

I'm getting this error in the logs:

[2021-05-17 13:34:03] local.ERROR: syntax error, unexpected token "try" {"exception":"[object] (ParseError(code: 0): syntax error, unexpected token \"try\" at /srv/www/api/packages/my-vendor/my-project/src/Http/Controllers/Auth/EmailVerificationController.php:71)

In my EmailVerificationController, at line 71, I have this:

public function verify(Request $request)
{
    try {
        if (Crypt::decrypt($request->route('hash')) != $request->user()->id) {
            abort(400);
        }
    } catch (DecryptException $e) {
        abort(400);
    }

    if ($request->user()->hasVerifiedEmail()) {
        return response('Email already verified.', 204);
    }

    if ($request->user()->markEmailAsVerified()) {
        return $request->user();
    }

    abort(400);
}

What's wrong with this method ?

0 likes
3 replies
abhijeet9920's avatar

Hello @devondahon ,

Can you add rest of the code inside try block and check?

<?php
	public function verify(Request  $request) {
		try {
			if (Crypt::decrypt($request->route('hash') != $request->user()->id) {
				abort(400);
			}
			if ($request->user()->hasVerifiedEmail()) {
				return  response('Email already verified.',  204);
			}
			if ($request->user()->markEmailAsVerified()) {
				return  $request->user();
			}
			abort(400);
		}catch (DecryptException  $e) {
			abort(400);
		}
	}
?>
devondahon's avatar
devondahon
OP
Best Answer
Level 3

@abhijeet9920 Thanks for your reply.

Indeed, I had typo in a log line at the beginning (missing semi column).

Unfortunately, I can't delete this post.

automica's avatar

@devondahon glad you solved your issue. mark your own answer as solved so people can see this topic is good.

Please or to participate in this conversation.