4
votes

I created a artisan command to clear application cache by following below link

http://code.tutsplus.com/tutorials/your-one-stop-guide-to-laravel-commands--net-30349

I'm trying to call it inside my Dashboard controller as below

namespace ABC;

class DashboardController extends \BaseController {

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    var $viewContent = [];

    public function index() {
        //Method one
        \Artisan::call('command:clearCache');

        //Method two
        $console=new \Illuminate\Console\Application;
        $console->call('command:clearCache');
        //Other function goes here

    }
 }

I got exception for above code (Method one in above code):

Call to undefined method Illuminate\Support\Facades\Artisan::call() Which means facades are not resolving to service providers.

for Method two, I got below exception

There are no commands defined in the "command" namespace.

I tried debugging using xdebug for 2 diffrent facades (One (App facade) is resolved where Artisan is not resolved correclty).

I know little bit about facades and how they work, but they are from laravel framework so help less.

Edit First two lines of providers array in config/app.php

'providers' => array(
        'Illuminate\Foundation\Providers\ArtisanServiceProvider',

First three line of aliases in config/app.php

 'aliases' => array(
        'App' => 'Illuminate\Support\Facades\App',
        'Artisan' => 'Illuminate\Support\Facades\Artisan',
3

3 Answers

2
votes

Thank you for your help.

I didn't get it worked the way i wanted, But I'm adding here a solution which is working for me. Hope it will work for someone else

    global $app;
    $artisan = new \Illuminate\Foundation\Artisan($app);
    $artisan->call('command:clearCache');

I checked my all facade and found couple of facade [Auth, Artisan] are not resolving correctly.

Hope it will help.

2
votes

Just to help out anyone who might have the same issue as myself. I only had trouble with Artisan being called, but I had the same error message as the OP.

It ended up being a permissions issue. Resetting the permissions on Storage and the Artisan file itself resolved this issue.

I do not know how or why the permissions changed.

1
votes

Try like this

\Artisan::call('clearCache');

You can pass any parameters as second argument

Artisan::call('clearCache', array('--paramname' => 'value'));