lundi 31 août 2015

Laravel: calling controller method from another location

In my Laravel app I have the following controller that takes the instance of Elastic search as a first parameter and then another variable:

use Elasticsearch\Client;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class AngularController extends Controller {
    public function selectRandom(Client $es, $numRows) {
        # ...search params here
        $results = $es->search($searchParams);
        return $results;
    }
}

I need to call the method of the controller above from another controller, I do it like this:

class HomeCtrl extends Controller {

    public function index() {

        $featured = new AngularController();

        return $featured->selectRandom(12);
    }

}

I get the following error

Argument 1 passed to App\Http\Controllers\AngularController::selectRandom() must be an instance of Elasticsearch\Client, integer given

I'm not well versed in OOP. Do I call it incorrectly? Because I though the method I call would take instance that it injected in controller, not from where I call it.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1NRUMzQ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire