当我尝试在laravel中发送重置密码链接时出现解析错误

I am using Laravel 5.4. I am getting error when i try to request password reset link.

Symfony\Component\Debug\Exception\FatalThrowableErrorPOST /password/email Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE)

File that error is pointing to is this ( at line 'return $next($request)'

app/Http/Middleware/RedirectIfAuthenticated.php:24App\Http\Middleware\RedirectIfAuthenticated::handle

 namespace App\Http\Middleware;
 use Closure; 
 use Illuminate\Support\Facades\Auth;

 class RedirectIfAuthenticated {
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string|null  $guard
  * @return mixed
  */
 public function handle($request, Closure $next, $guard = null)
 {
     if (Auth::guard($guard)->check()) {
         return redirect('/');
     }

     return $next($request);
 } 
}

I debugged further into code and found out that this function is prolly causing issue.
FILE NAME:Symfony\Component\CssSelector\XPath\Extension\AttributeMatchingExtension

public function translateExists(XPathExpr $xpath, string $attribute, ?string $value): XPathExpr
{
    return $xpath->addCondition($attribute);
}

I had the same issue with php 7.0.23 and Laravel 5.5 using the php mail() function:

Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) at [...]/vendor/symfony/css-selector/XPath/Extension/AttributeMatchingExtension.php:46

The problem was solved by upgrading to version php 7.1+. (php 7.1.9 in my case)