問題描述
我是 Laravel 的新手(只體驗(yàn)過 Laravel 5,所以這里沒有遺留問題)
我想知道如何擴(kuò)展核心請求類.除了如何擴(kuò)展它之外,我想知道這樣做是否是一個(gè)明智的設(shè)計(jì)決定.
我已經(jīng)廣泛閱讀了文檔(特別是關(guān)于注冊服務(wù)提供者以及它提供 Facades 訪問依賴項(xiàng)容器內(nèi)的條目的方式) - 但我可以看到(并找到)沒有辦法替換 IlluminateHttpRequest
實(shí)例與我自己的
這里是官方文檔:Request Lifecycle >
app/Http/CustomRequest.php 的內(nèi)容
將此行添加到 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()
這篇關(guān)于在 Laravel 5 中擴(kuò)展請求類的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!