nulele

Experience

60

0 Best Reply Awards

  • Member Since 7 Months Ago
  • 0 Lessons Completed
  • 0 Favorites

9th August, 2017

nulele left a reply on Execution Order In Controller's Constructor With Middleware (Laravel 5.4) • 2 months ago

Thank you Parasoul but your link is about using sessions in controller's construct... maybe I'm wrong but this has nothing to do with my problem that it seems more general.

My problem is about the execution order of code in the constructor itself.

7th August, 2017

nulele started a new conversation Execution Order In Controller's Constructor Whit Middleware • 2 months ago

Hello,

I'ma facengo a weird problem on execution order inside a controller's constructor.

Consider this Controller code:

public function __construct()
{
        $this->middleware(MyMiddleware::class);

        echo "2";
 }

And MyMiddleware code:

public function handle($request, Closure $next)
{
    echo "1";

    return $next($request);
}

When I execute the request, I get 2 and 1!

WHY?

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.