fideloper が彼の記事で言及しているように、クラスの拡張はRequest
通常のクラスとは少し異なります。ただし、より単純です。
1.拡張Request
クラスを作成し、オートロードできることを確認します。
ExtendedRequest.php
namespace Raphael\Extensions;
use Illuminate\Support\Facades\Response as IlluminateResponse;
class Response extends IlluminateResponse {
public function isSecure() {
return true;
}
}
isSecure
の代わりにメソッドを拡張したことに注意してくださいsecure
。これは、secure
単にisScure
Symfony の基本Request
クラスから , を呼び出すためです。
2. Laravel が拡張クラスを使用していることを確認します。これを行うには、start.phpファイルを変更します。
ブートストラップ/start.php
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/
use Illuminate\Foundation\Application;
Application::requestClass('Raphael\Extensions\Request');
$app = new Application;
$app->redirectIfTrailingSlash();
3. app.php設定ファイルに正しいエイリアスが設定されていることを確認してください。
アプリ/設定/app.php
'aliases' => array(
// ...
'Request' => 'Raphael\Extensions\Request',
// ...
),