1

I am using Laravel.

And I have a controller action, which get the orders' information by date. and sum all the amount of orders, and it will return datas.

And I want to call it in Console\Command script so I don't need to repeat the same code, just get those datas from action.

Please help me how to do it?

1

2 Answers 2

1

Do something like this:

Without parameters:

\App::call('App\Http\Controllers\MyController@actionName')

If you have Request parameters:

$request = new \Illuminate\Http\Request($datas);
$controller = app()->make(MyController::class);
$Response = $controller->callAction('ActionName',[$request]);

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

Comments

0

I wanted to call the CreateNewUser action from the FortifyServiceProvider. It took me some time to find out, but it is quite simple:

use App\Actions\Fortify\CreateNewUser;

// Use fortify to create a new user.
$new_user_action = new CreateNewUser();
$user = $new_user_action->create($input);

Comments

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.