Search code examples
phplaravellaravel-4laravel-facade

Laravel 4.2 Illuminate Facade are not getting resolved


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',

Solution

  • 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.