Ibrahim AshShohail
Ibrahim AshShohail

Reputation: 2182

Run an artisan command from a Laravel app

In Laravel's artisan can be used to execute many tasks including migrations, generation of resources...etc.

In Laravel 4, how could you run an artisan command from you app without using shell_exec?

Upvotes: 1

Views: 3185

Answers (2)

Tihomir
Tihomir

Reputation: 73

This is how you can get command output:

<?php

use Symfony\Component\Console\Output\StreamOutput;

class MyClass 
{
    public function myFunc()
    {
        $stream = fopen("php://output", "w");

        Artisan::call('my-command', array(), new StreamOutput($stream));

        var_dump($stream);
    }

}

Upvotes: 1

Holger Weis
Holger Weis

Reputation: 1695

You run Artisan commands via Artisan::call, for example:

Artisan::call('migrate')

Upvotes: 8

Related Questions