0

I have a function of the controller where it calls me a command where I must pass it a list of projects that were assigned to a translation so that it looks for me in another table and registers them as recurrent contacts.

The issue is that I can not execute the command always throws me an error and I made the reference and nothing.

It throws me problems because I want to pass parameters to the command.

Controller

public function syncTranslate(Request $request,Project $project){
        $this->authorize('update translate', TranslateProject::class);
        
        $translateWithouthProyect = TranslateProject::filterData()->get();
       
        Artisan::call('fidelizaleads:quotesWithoutProjects',$translateWithouthProyect);
        exit;

return redirect()->route('translate.index')->with(notify()->success($count .' traducciones fueron añadidas al proyecto '. $project->name));

    }

Command

protected $signature = 'fidelizaleads:quotesWithoutProjects';

 protected $translate;
    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct($translate)
    {
        parent::__construct();
        $this->translate = $translate;
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        Quote::executeQuoteTranslation($this->translate);
        
    }

And this is the error message he throws at me

enter image description here

1 Answer 1

1

I would have to guess that you are passing a Collection as the second argument to call. You would have to ask that Collection for the underlying array:

Artisan::call('fidelizaleads:quotesWithoutProjects', $translateWithouthProyect->toArray());

You can use toArray() on the Collection to get the array.

Though I am not sure what passing that array is going to do as you don't have any parameters for that command and the array is usually an associative array.

Sign up to request clarification or add additional context in comments.

4 Comments

If it is an object array it is like a SELECT * FROM TRANSLATE WHERE PROJECT_ID IS NULL; @lagbox
what type of object is it? as you can't pass an object as the second parameter ... and your command doesn't take parameters
I don't know how to add parameters to the commands, first time I work with them.?
laravel.com/docs/8.x/artisan#defining-input-expectations check out that part of the docs or the doc version for what ever version you are using

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.