Extend Request class in Laravel 5

I was working on the same issue today and I think it's worth mention that you may just change

Illuminate\Http\Request::capture()

to

App\Http\CustomRequest::capture()

without adding line

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

because inside capture() method laravel actually binds provided class to service container with 'request' as a key


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