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

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

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)