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

ApolloBLN's avatar

Laravel arrow functions

Was just trying arrow functions within a factory.

$factory->define(Thread::class, function (Faker $faker) {

return [
    'user_id'    => function () {
        return factory(App\User::class)->create()->id;
    },
    'channel_id' => fn() => factory('App\Channel')->create()->id,
    'title'      => $faker->text,
    'body'       => $faker->paragraph];

});

But I get this error: PHP Error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in...

0 likes
3 replies
ApolloBLN's avatar

Im using phpstorm with php 7.4 so !? Actually the terminal section apparently was still running 7.2 after a restart it's 7.4 now. But now its just stuck when I try:

App\Thread {#3037}

factory(App\Thread::class,10)->make() I get a timeout, this only occurs with php 7.4 in laravel tinker, aside from using arrow functions or not

PDOException with message 'SQLSTATE[HY000] [2006] MySQL server has gone away'

Please or to participate in this conversation.