Problem You want to call any registered shutdown functions directly. You’re exiting your Laravel application in a non-standard way, and want to call any shutdown callbacks that have been registered with your application. Solution Use App::shutdown() You can
Problem You want to execute code just before your application finishes. Solution Register a Shutdown callback. Discussion Shutdown callbacks occur after the response has been sent to the user. They occur during the shutdown process, right before the application exits.
Problem You want to do work after every request in your application. Solution Register a “after” application filter. Discussion You can modify the response. Since after filters receive the response object, you can make changes to the response within this filter.
Problem PHP cannot instantiate interfaces But you like to write beautiful code following SOLID design principles. How can you make interfaces automatically resolve into concrete classes? Solution Use App::bind() Now, with the above code, whenever you
Problem You want to check if your application is running in the console. You know you can check php_sapi_name() but would like to use the more elegant, Laravel way. Solution Use App::runningInConsole() Discussion Laravel actually uses php_sapi_name() to
Problem You need to know the environment. You’ve reached a point in your application where it would be handy to know what your environment is, but aren’t sure the best way to determine this. Solution There are several If you’re specifically checking
Problem You want to assign a variable in a Blade template. Solution Blade does not provide a command to do this. The idea is to cleanly separate logic from presentation. But in the case where it’s more expedient to assign a variable in a template, here’s a couple