seamus
seamus

Reputation: 2901

Laravel: How to use Artisan Facade to call terminal commands in Controllers & Models

I have the following 'artisan' command set up

protected $signature = 'make:sub {type} {name}';

The above command works when typed into the terminal.

I want to call it dynamically in a controller. Below is my code:

    $name = $request->input("name");

    Artisan::call('make:sub', [
        'type' => 'origin', 'name' => $name
    ]);

The above is not working.

I think the issue might be the 'artisan namespace'.

What is the correct 'use namespace' to call artisan commands set up in the command folder?

Upvotes: 0

Views: 854

Answers (1)

Giorgi Lagidze
Giorgi Lagidze

Reputation: 831

You got 2 options.

1) at the beginning of the file, you can type: use Artisan;

2) just type :

\Artisan::call('make:sub', [
     'type' => 'origin', 'name' => $name
]);

Upvotes: 1

Related Questions