Extend Request class in 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 中扩展请求类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Laravel 5 中扩展请求类
基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何替换eregi() 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
