問題描述
我是 Laravel 的新手(只體驗過 Laravel 5,所以這里沒有遺留問題)
我想知道如何擴展核心請求類.除了如何擴展它之外,我想知道這樣做是否是一個明智的設計決定.
我已經廣泛閱讀了文檔(特別是關于注冊服務提供者以及它提供 Facades 訪問依賴項容器內的條目的方式) - 但我可以看到(并找到)沒有辦法替換 IlluminateHttpRequest
實例與我自己的
這里是官方文檔:Request Lifecycle >
app/Http/CustomRequest.php 的內容
將此行添加到 public/index.php
$app->alias('request', 'AppHttpCustomRequest');
之后
app = require_once __DIR__.'/../bootstrap/app.php';
更改 public/index.php 中的代碼
IlluminateHttpRequest::capture()
到
AppHttpCustomRequest::capture()
I'm new to Laravel (only experienced Laravel 5, so no legacy hang up here)
I'd like to know how to extend the core Request class. In addition to how to extend it, i'd like to know if it's a wise design decision to do so.
I've read through the documentation extensively (especially with regards to registering service providers and the manner in which it provides Facades access to entries within the dependency container) - but I can see (and find) no way to replace the IlluminateHttpRequest
instance with my own
Here is Official Document: Request Lifecycle
Content of app/Http/CustomRequest.php
<?php namespace AppHttp;
use IlluminateHttpRequest as BaseRequest;
class CustomRequest extends BaseRequest {
// coding
}
add this line to public/index.php
$app->alias('request', 'AppHttpCustomRequest');
after
app = require_once __DIR__.'/../bootstrap/app.php';
change the code at public/index.php
IlluminateHttpRequest::capture()
to
AppHttpCustomRequest::capture()
這篇關于在 Laravel 5 中擴展請求類的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!