在Laravel 5中扩展Request类 [英] Extend Request class in Laravel 5

查看:68
本文介绍了在Laravel 5中扩展Request类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Laravel的新手(只有经验丰富的Laravel 5,所以这里没有遗留物)

我想知道如何扩展核心Request类.除了如何扩展它,我想知道这样做是否是明智的设计决定.

我已经仔细阅读了文档(特别是关于注册服务提供商以及它向Facades提供对依赖容器中条目的访问的方式)-但我看不到(找到)无法替换\Illuminate\Http\Request具有我自己的实例

解决方案

以下是正式文档:请求生命周期

app/Http/CustomRequest.php的内容

<?php namespace App\Http;

use Illuminate\Http\Request as BaseRequest;

class CustomRequest extends BaseRequest {
    // coding
}

将此行添加到public/index.php

$app->alias('request', 'App\Http\CustomRequest');

之后

app = require_once __DIR__.'/../bootstrap/app.php';

在public/index.php上更改代码

Illuminate\Http\Request::capture()

App\Http\CustomRequest::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 \Illuminate\Http\Request instance with my own

解决方案

Here is Official Document: Request Lifecycle

Content of app/Http/CustomRequest.php

<?php namespace App\Http;

use Illuminate\Http\Request as BaseRequest;

class CustomRequest extends BaseRequest {
    // coding
}

add this line to public/index.php

$app->alias('request', 'App\Http\CustomRequest');

after

app = require_once __DIR__.'/../bootstrap/app.php';

change the code at public/index.php

Illuminate\Http\Request::capture()

to

App\Http\CustomRequest::capture()

这篇关于在Laravel 5中扩展Request类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆