💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### **Request Extension** ### Because it is such a foundational piece of the framework and is instantiated very early in the request cycle, extending the ``Request`` class works a little differently than the previous examples. First, extend the class like normal: ~~~ <!-- lang:php --> namespace QuickBill\Extensions; class Request extends \Illuminate\Http\Request { // Custom, helpful methods here... } ~~~ Once you have extended the class, open the ``bootstrap/start.php`` file. This file is one of the very first files to be included on each request to your application. Note that the first action performed is the creation of the Laravel ``$app`` instance: ~~~ <!-- lang:php --> $app = new \Illuminate\Foundation\Application; ~~~ When a new application instance is created, it will create a new ``Illuminate\Http\Request`` instance and bind it to the IoC container using the ``request`` key. So, we need a way to specify a custom class that should be used as the "default" request type, right? And, thankfully, the ``requestClass`` method on the application instance does just this! So, we can add this line at the very top of ``our bootstrap/start.php`` file: ~~~ <!-- lang:php --> use Illuminate\Foundation\Application; Application::requestClass('QuickBill\Extensions\Request'); ~~~ Once you have specified the custom request class, Laravel will use this class anytime it creates a ``Request`` instance, conveniently allowing you to always have an instance of your custom request class available, even in unit test!