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

boyjarv's avatar

php artisan route:list shows error in code

when I run php artisan route:list on my server, I get:

syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')'

  at app/Http/Controllers/TodoController.php:34
     30▕         // return response()->json($todos->toArray());
     31▕ 
     32▕         $todos = $this->user
     33▕ 		->todos()
  ➜  34▕ 		->when(request()->has('limit'), fn ($builder) => $builder->take(request('limit')))
     35▕         ->get(['id', 'title', 'body', 'completed', 'created_by']);
     36▕         return response()->json($todos->toArray());
     37▕     }
     38▕     
0 likes
5 replies
tykus's avatar

Check that your CLI version of PHP is >= 7.4 so that you can support short closures, e.g.

$ php -v
PHP 7.4.9 (cli) (built: Aug  7 2020 19:23:06) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies
boyjarv's avatar

PHP 7.3.27, how can I update it to 7.4 using command line?

tykus's avatar

You can expand to the long Closure syntax:

->when(request()->has('limit'), function ($builder) {
	$builder->take(request('limit'));
})
1 like

Please or to participate in this conversation.