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

j00rd's avatar
Level 2

Arrow functions not working => Returns unexpected '=>' (T_DOUBLE_ARROW), expecting ')'

Hi guys,

I'm following along with Laravel from Scratch 8 however I've encountered a problem whenever trying to use the same code as Jeffery.

My code for searching works like this :

$query->when($filters['search'] ?? false, function ($query, $search) { $query ->where('title', 'like', '%' . $search . '%') ->orWhere('body', 'like', '%' . $search . '%'); });

Where as Jeffery moves on to this code:

$query->when($filters['search'] ?? false, fn($query, $search) => $query->where(fn($query) => $query->where('title', 'like', '%' . $search . '%') ->orWhere('body', 'like', '%' . $search . '%') ) );

The first way works fine for the initial search however when trying to use the => as shown next in the video I'm getting the Syntax error from the title. It wasn't a problem just for the search but moving on to episode 39, the search through categories I'm now following the video using => and it's just kicking up the same error. I've used "php artisan --version" to check and I'm on 8.64.0, also using "app()->version()" to double check along side the composer.json file so I'm definitely using the up to date version.

Any ideas where I'm going wrong? Thank you!

0 likes
3 replies
j00rd's avatar
Level 2

Haha I'm so dumb, I read that multiple times but was checking my Laravel version not the php, thank you!

Please or to participate in this conversation.