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

ulian's avatar
Level 2

trim() expects parameter 1 to be string, array given - php artisan event:generate

Hi,

I'm trying to generate an event to execute some code when a user login, when I execute "php artisan event:generate" an error is thrown. My $listen variable at EventServiceProvider.php is declared as:

protected $listen = [
    Registered::class => [
        SendEmailVerificationNotification::class,
        'Illuminate\Auth\Events\Login' => [
            'App\Listeners\LogSuccessfulLogin',
        ],
    ],
];

Error:

$ php artisan event:generate

   ErrorException  : trim() expects parameter 1 to be string, array given

  at ...\vendor\laravel\framework\src\Illuminate\Console\GeneratorCommand.php:215
    212|      */
    213|     protected function getNameInput()
    214|     {
  > 215|         return trim($this->argument('name'));
    216|     }
    217|
    218|     /**
    219|      * Get the root namespace for the class.

  Exception trace:

  1   trim()
      ..\vendor\laravel\framework\src\Illuminate\Console\GeneratorCommand.php:215

  2   Illuminate\Console\GeneratorCommand::getNameInput()
      ..\vendor\laravel\framework\src\Illuminate\Console\GeneratorCommand.php:53

  Please use the argument -v to see more details.

I add dd(gettype($this->argument('name')), $this->argument('name')); to debug the problem and output is:

"string"
"Illuminate\Auth\Events\Registered"

Laravel version 5.8.2 Laravel Installer 2.0.1

Probably I'm doing something wrong, I can't tell what.

Thanks!

0 likes
2 replies
Nakov's avatar
Nakov
Best Answer
Level 73

The way you have set your $listen array is wrong I believe, the structure should be

$listen = [
event => [listeners],
event => [listeners]
]

so change it to this:

protected $listen = [
    Registered::class => [
        SendEmailVerificationNotification::class
    ],
    'Illuminate\Auth\Events\Login' => [
        'App\Listeners\LogSuccessfulLogin',
    ],
];
2 likes
ulian's avatar
Level 2

Yes, that was the issue. Thank you.

Please or to participate in this conversation.