3 years ago

IOC from Controller

Posted 3 years ago by codenex

How do I get access to the IOC container from within a controller?

I have moved some logic out of the routes file and am now using a controller. I could use the IOC from the $app variable in route without an issue

$app->get('/', function () use ($app) {
    return $app->version();

However if I change this to send to a controller

$app->get('/', '[email protected]');
// HomeController
class HomeController extends Controller
    public function index()
        return $app->version();

Then I get the following error:

Undefined variable: app

Please sign in or create an account to participate in this conversation.