Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
198 views
Welcome To Ask or Share your Answers For Others

1 Answer

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()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...