Support the ongoing development of Laravel.io →
posted 10 years ago
Authentication

Does anyone know why the middleware in the following example is not working?

class PageController extends Controller {

  public function __construct() {

       $this->middleware('auth');

  }

  public function home() {

      return view('home');

  }

}

// this line is executed from within another middleware:

\App::make('PageController');

I've also tried:

\App::call('PageController@home'); 

but it doesn't work either.

However If I call the controller from my route it works like expected:

Route::get('test', 'PageController@home');

But I need to call the controller from another middleware and not directly from a route.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

zlatevbg zlatevbg Joined 3 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.