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▕
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
PHP 7.3.27, how can I update it to 7.4 using command line?
can I not just change my code?
You can expand to the long Closure syntax:
->when(request()->has('limit'), function ($builder) {
$builder->take(request('limit'));
})
Please or to participate in this conversation.