Readouble

Laravel 4.2 リクエストと入力

入力の基本Basic Input

いくつかのシンプルなメソッドを用い、ユーザーの入力全部にアクセスできます。リスエストに使用されるHTTP動詞に惑わされる必要はありません。同じやり方で全ての変数にアクセスできます。You may access all user input with a few simple methods. You do not need to worry about the HTTP verb used for the request, as input is accessed in the same way for all verbs.

一つの値を取得するRetrieving An Input Value

$name = Input::get('name');

入力値が存在しない場合に、デフォルト値を取得するRetrieving A Default Value If The Input Value Is Absent

$name = Input::get('name', 'Sally');

入力値が存在するか確かめるDetermining If An Input Value Is Present

if (Input::has('name'))
{
	//
}

リクエストの全入力を取得するGetting All Input For The Request

$input = Input::all();

限定されたリクエスト入力のみ取得するGetting Only Some Of The Request Input

$input = Input::only('username', 'password');

$input = Input::except('credit_card');

「配列」入力を使ったフォームを動作させる場合、ドット記法を使い、配列にアクセスできます。When working on forms with "array" inputs, you may use dot notation to access the arrays:

$input = Input::get('products.0.name');

**注目:**BackboneのようなJavascriptライブラリーはJSONでアプリケーションに入力を送ってくることでしょう。 通常と同じくInput::getでアクセス可能です。Note: Some JavaScript libraries such as Backbone may send input to the application as JSON. You may access this data via Input::get like normal.

クッキーCookies

Laravelフレームワークで生成された全てのクッキーは暗号化され、認証コードで署名されます。これが意味するのは、もしクライアントにより改変されれば無効になるということです。All cookies created by the Laravel framework are encrypted and signed with an authentication code, meaning they will be considered invalid if they have been changed by the client.

一つのクッキーの値を取得するRetrieving A Cookie Value

$value = Cookie::get('name');

レスポンスに新しいクッキーを付けるAttaching A New Cookie To A Response

$response = Response::make('Hello World');

$response->withCookie(Cookie::make('name', 'value', $minutes));

次のレスポンスのためにクッキーをキューイングするQueueing A Cookie For The Next Response

レスポンスが生成される前に、クッキーを予めセットしておきたい場合は、Cookie::queue()メソッドを使用してください。アプリケーションから最終的にレスポンスが返される時に、自動的にそのクッキーを添付します。If you would like to set a cookie before a response has been created, use the Cookie::queue() method. The cookie will automatically be attached to the final response from your application.

Cookie::queue($name, $value, $minutes);

永久に残るクッキーを生成するCreating A Cookie That Lasts Forever

$cookie = Cookie::forever('name', 'value');

直前の入力Old Input

あるレスポンスの入力を次のリクエストまで取っておく必要もあるでしょう。例えば、バリデーションをチェックした後のエラーで、フォームの内容を再表示する場合です。You may need to keep input from one request until the next request. For example, you may need to re-populate a form after checking it for validation errors.

セッションに入力値を保存するFlashing Input To The Session

Input::flash();

セッションに入力をいくつか保存するFlashing Only Some Input To The Session

Input::flashOnly('username', 'email');

Input::flashExcept('password');

しばしば以前のページヘのリダイレクトで、関係する入力を保存したい場合が起きます。リダイレクトにチェーンで入力を保存するように指定できます。Since you often will want to flash input in association with a redirect to the previous page, you may easily chain input flashing onto a redirect.

return Redirect::to('form')->withInput();

return Redirect::to('form')->withInput(Input::except('password'));

**注目:**その他のデーターを次のリクエストで使用したい場合は、セッションクラスを使用できます。Note: You may flash other data across requests using the Session[/docs/4.2/session] class.

直前のデーターを取得するRetrieving Old Data

Input::old('username');

ファイルFiles

アップデートしたファイルを取得するRetrieving An Uploaded File

$file = Input::file('photo');

ファイルがアップロードされたか調べるDetermining If A File Was Uploaded

if (Input::hasFile('photo'))
{
	//
}

fileメソッドがリターンするのは、Symfony\Component\HttpFoundation\File\UploadedFileクラスのインスタンスで、PHPのSplFileInfoを拡張しています。それにはファイルに関する様々なメソッドが提供されています。The object returned by the file method is an instance of the Symfony\Component\HttpFoundation\File\UploadedFile class, which extends the PHP SplFileInfo class and provides a variety of methods for interacting with the file.

Determining If An Uploaded File Is ValidDetermining If An Uploaded File Is Valid

if (Input::file('photo')->isValid())
{
	//
}

アップロードしたファイルを削除するMoving An Uploaded File

Input::file('photo')->move($destinationPath);

Input::file('photo')->move($destinationPath, $fileName);

アップロードしたファイルのパスを取得するRetrieving The Path To An Uploaded File

$path = Input::file('photo')->getRealPath();

アップロードしたファイルの元の名前を取得するRetrieving The Original Name Of An Uploaded File

$name = Input::file('photo')->getClientOriginalName();

アップロードしたファイルの拡張子を取得するRetrieving The Extension Of An Uploaded File

$extension = Input::file('photo')->getClientOriginalExtension();

アップロードしたファイルのサイズを取得するRetrieving The Size Of An Uploaded File

$size = Input::file('photo')->getSize();

アップロードしたファイルのMIMEタイプを取得するRetrieving The MIME Type Of An Uploaded File

$mime = Input::file('photo')->getMimeType();

リクエスト情報Request Information

Requestクラスはアプリケーションに対するHTTPリクエストを調べるための多くのメソッドを提供しており、Symfony\Component\HttpFoundation\Requestを拡張しています。その特徴のいくつかをご覧ください。The Request class provides many methods for examining the HTTP request for your application and extends the Symfony\Component\HttpFoundation\Request class. Here are some of the highlights.

リクエストされたURIを取得するRetrieving The Request URI

$uri = Request::path();

リクエストのメソッドを取得するRetrieving The Request Method

$method = Request::method();

if (Request::isMethod('post'))
{
	//
}

リクエスされたパスがパターンと一致するか調べるDetermining If The Request Path Matches A Pattern

if (Request::is('admin/*'))
{
	//
}

リクエストされたURLを取得するGet The Request URL

$url = Request::url();

リクエストのURIセグメントを取得するRetrieve A Request URI Segment

$segment = Request::segment(1);

リクエストヘッダーを取得するRetrieving A Request Header

$value = Request::header('Content-Type');

$_SERVERから値を取得するRetrieving Values From $_SERVER

$value = Request::server('PATH_INFO');

リクエストがHTTPSを用いられたものか調べるDetermining If The Request Is Over HTTPS

if (Request::secure())
{
	//
}

リクエストがAJAXを用いられたものか調べるDetermine If The Request Is Using AJAX

if (Request::ajax())
{
	//
}

リクエストはJSONコンテツタイプを持っているか判定するDetermine If The Request Has JSON Content Type

if (Request::isJson())
{
	//
}

リスエストがJSONを要求しているか判定するDetermine If The Request Is Asking For JSON

if (Request::wantsJson())
{
	//
}

リクエストされているレスポンスのフォーマットを確認するChecking The Requested Response Format

Request::formatメソッドは、HTTP Acceptヘッダーに基づき、要求されているリクエストのフォーマットを返します。The Request::format method will return the requested response format based on the HTTP Accept header:

if (Request::format() == 'json')
{
	//
}

章選択

Artisan CLI

設定

明暗テーマ
light_mode
dark_mode
brightness_auto システム設定に合わせる
テーマ選択
photo_size_select_actual デフォルト
photo_size_select_actual モノクローム(白黒)
photo_size_select_actual Solarized風
photo_size_select_actual GitHub風(青ベース)
photo_size_select_actual Viva(黄緑ベース)
photo_size_select_actual Happy(紫ベース)
photo_size_select_actual Mint(緑ベース)
コードハイライトテーマ選択

明暗テーマごとに、コードハイライトのテーマを指定できます。

テーマ配色確認
スクリーン表示幅
640px
80%
90%
100%

768px以上の幅があるときのドキュメント部分表示幅です。

インデント
無し
1rem
2rem
3rem
原文確認
原文を全行表示
原文を一行ずつ表示
使用しない

※ 段落末のEボタンへカーソルオンで原文をPopupします。

Diff表示形式
色分けのみで区別
行頭の±で区別
削除線と追記で区別

※ [tl!…]形式の挿入削除行の表示形式です。

テストコード表示
両コード表示
Pestのみ表示
PHPUnitのみ表示
和文変換

対象文字列と置換文字列を半角スペースで区切ってください。(最大5組各10文字まで)

本文フォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

コードフォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

保存内容リセット

localStrageに保存してある設定項目をすべて削除し、デフォルト状態へ戻します。

ヘッダー項目移動

キーボード操作