mostafalaravel
2 months ago
264
2
Laravel

custom command : ask password

Posted 2 months ago by mostafalaravel

Hello ,

I'm wondering if it's possible to ask user to type something like password when he run a custom method ?

<?php

namespace App\Console\Commands;

use App\User;
use Illuminate\Console\Command;

class CreateAdminUser extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'create:admin';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create a new user with admin roles. Be sure you create it following your roles implementation';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $user = User::create([
            'name' => 'Jhon Doe',
            'email' => '[email protected]',
            'password' => bcrypt('password'),
            'admin' => true
        ]);
        if($user){
            $this->info('Admin user successfully created the email is [email protected] and the password is "password" ');
        }
    }
}

Thanks

Please sign in or create an account to participate in this conversation.