0
votes

I'm trying to make a new custom entry in the /routes/console.php file so I can create a user from the cli.

I have a custom function that can create a user in \app\Http\Controllers\UserManagement
It's called createUser() and accepts 3 params ($user,$email,$password)

So far I have

Artisan::command('createuser {$user} {$email} {$password}', function ($user,$email,$password) { $this->createUser($user,$email,$password); })->describe('Create a user via the CLI');

Currently this errors with

Too few arguments to function Illuminate\Foundation\Console\ClosureCommand::__construct(), 1 passed in \vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php on line 208 and exactly 2 expected

2

2 Answers

0
votes

Remove the $ from the first parameter. Should look like this

Artisan::command('createuser {user} {email} {password}', function ($user, $email, $password) {
    $this->createUser($user, $email, $password);
})->describe('Create a user via the CLI');
0
votes

The problem was that I needed to type hint the dependency on my class.

use App\Http\Controllers\UserManagerController;

Artisan::command('createuser {user} {email} {password}', function (UserManagerController $ref, $user, $email, $password) {
    $ref->createUser($user, $email, $password);
})->describe('Create a user via the CLI');