R
R
roman99662016-10-05 13:18:31
Laravel
roman9966, 2016-10-05 13:18:31

How to call a class method that is passed as an option in the artisan command?

In Lumen I want to make a command that will parse data and enter it into the database, the option of this command will be the name of the class that will perform the parsing, i.e. something like this
php artisan parse --service=SomeParser
Can I do this in the method that is called when executing the command:

$this->getLaravel()->call($this->arguments('service') . '@parse')

The method parsewill take the data and put it into the database. All parser classes implement a common interface in which the method is defined. parse
Maybe there are some other options?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
roman9966, 2016-10-06
@roman9966

With this option, you need to specify the class name with a namespace. This option, although it works, looks like a crutch. It would be better to call some factory class in the command and pass the name of the parser there, which, in principle, I did.

A
Alex Wells, 2016-10-05
@Alex_Wells

First, stop using Lumen. It is suitable for a business card site with reviews.
Secondly, did you test the functionality of the specified code, or not?)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question