jeudi 17 octobre 2019

Access Arguments Input via Artisan Console Command

I want to run my command like this

php artisan update:code --code=123

I want to get the code from first argument - I can't seems to find a way to do it on Laravel site.

<?php

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

class updateCode extends Command
{

    protected $signature = 'update:code {code}';


    protected $description = 'Update Code ... ';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {

        $code         = $this->option('code');
        $this->info($code);
        $user         = User::where('type','Admin')->first();
        $user->code   = bcrypt($code);
        $user->active = 1;
        $user->save();

        $this->info($user);

    }
}

I kept getting

The "--code" option does not exist.

Do I need to defind my option too ?

How can I just quickly access the first argument ?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/35JvKk8
via IFTTT

Aucun commentaire:

Enregistrer un commentaire