Quantcast
Channel: Access Arguments Input via Artisan Console Command - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Access Arguments Input via Artisan Console Command

$
0
0

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 ?


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>