在 Laravel 5 中扩展请求类

Extend Request class in Laravel 5(在 Laravel 5 中扩展请求类)
本文介绍了在 Laravel 5 中扩展请求类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我是 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 中扩展请求类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

In PHP how can you clear a WSDL cache?(在 PHP 中如何清除 WSDL 缓存?)
failed to open stream: HTTP wrapper does not support writeable connections(无法打开流:HTTP 包装器不支持可写连接)
Stop caching for PHP 5.5.3 in MAMP(在 MAMP 中停止缓存 PHP 5.5.3)
Caching HTTP responses when they are dynamically created by PHP(缓存由 PHP 动态创建的 HTTP 响应)
Memcached vs APC which one should I choose?(Memcached 与 APC 我应该选择哪一个?)
What is causing quot;Unable to allocate memory for poolquot; in PHP?(是什么导致“无法为池分配内存?在 PHP 中?)