Readouble

Laravel 5.4 ヘルパ

イントロダクションIntroduction

Laravelは様々な、グローバル「ヘルパ」PHP関数を用意しています。これらの多くはフレームワーク自身で使用されています。便利なものが見つかれば、皆さんのアプリケーションでも大いに活用してください。Laravel includes a variety of global "helper" PHP functions. Many of these functions are used by the framework itself; however, you are free to use them in your own applications if you find them convenient.

使用可能な関数Available Methods

配列Arrays

パスPaths

文字列Strings

URLURLs

その他Miscellaneous

メソッド一覧Method Listing

配列Arrays

array_add() {#collection-method .first-collection-method}array_add() {#collection-method .first-collection-method}

array_add関数は指定されたキー/値のペアをそのキーが存在していない場合、配列に追加します。The array_add function adds a given key / value pair to the array if the given key doesn't already exist in the array:

$array = array_add(['name' => 'Desk'], 'price', 100);

// ['name' => 'Desk', 'price' => 100]

array_collapse() {#collection-method}array_collapse() {#collection-method}

array_collapse関数は配列の配列を一次元の配列へ展開します。The array_collapse function collapses an array of arrays into a single array:

$array = array_collapse([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);

// [1, 2, 3, 4, 5, 6, 7, 8, 9]

array_divide() {#collection-method}array_divide() {#collection-method}

array_divide関数は2つの配列をリターンします。一つはオリジナル配列のキー、もう一方は値です。The array_divide function returns two arrays, one containing the keys, and the other containing the values of the original array:

list($keys, $values) = array_divide(['name' => 'Desk']);

// $keys: ['name']

// $values: ['Desk']

array_dot() {#collection-method}array_dot() {#collection-method}

array_dot関数は多次元配列を「ドット」記法で深さを表した一次元配列に変換します。The array_dot function flattens a multi-dimensional array into a single level array that uses "dot" notation to indicate depth:

$array = array_dot(['foo' => ['bar' => 'baz']]);

// ['foo.bar' => 'baz'];

array_except() {#collection-method}array_except() {#collection-method}

array_except関数は指定されたキー/値ペアを配列から削除します。The array_except function removes the given key / value pairs from the array:

$array = ['name' => 'Desk', 'price' => 100];

$array = array_except($array, ['price']);

// ['name' => 'Desk']

array_first() {#collection-method}array_first() {#collection-method}

array_first関数は指定されたテストにパスした最初の要素を返します。The array_first function returns the first element of an array passing a given truth test:

$array = [100, 200, 300];

$value = array_first($array, function ($value, $key) {
    return $value >= 150;
});

// 200

デフォルト値を3つ目の引数で指定することもできます。この値はテストでどの値もテストにパスしない場合に返されます。A default value may also be passed as the third parameter to the method. This value will be returned if no value passes the truth test:

$value = array_first($array, $callback, $default);

array_flatten() {#collection-method}array_flatten() {#collection-method}

array_flatten関数は、多次元配列を一次元配列へ変換します。The array_flatten function will flatten a multi-dimensional array into a single level.

$array = ['name' => 'Joe', 'languages' => ['PHP', 'Ruby']];

$array = array_flatten($array);

// ['Joe', 'PHP', 'Ruby'];

array_forget() {#collection-method}array_forget() {#collection-method}

array_forget関数は「ドット記法」で指定されたキーと値のペアを深くネストされた配列から取り除きます。The array_forget function removes a given key / value pair from a deeply nested array using "dot" notation:

$array = ['products' => ['desk' => ['price' => 100]]];

array_forget($array, 'products.desk');

// ['products' => []]

array_get() {#collection-method}array_get() {#collection-method}

array_get関数は指定された値を「ドット」記法で指定された値を深くネストされた配列から取得します。The array_get function retrieves a value from a deeply nested array using "dot" notation:

$array = ['products' => ['desk' => ['price' => 100]]];

$value = array_get($array, 'products.desk');

// ['price' => 100]

array_get関数は、指定したキーが存在しない場合に返されるデフォルト値を指定できます。The array_get function also accepts a default value, which will be returned if the specific key is not found:

$value = array_get($array, 'names.john', 'default');

array_has() {#collection-method}array_has() {#collection-method}

array_has関数は、「ドット」記法で指定されたアイテムの存在をチェックします。The array_has function checks that a given item or items exists in an array using "dot" notation:

$array = ['product' => ['name' => 'desk', 'price' => 100]];

$hasItem = array_has($array, 'product.name');

// true

$hasItems = array_has($array, ['product.price', 'product.discount']);

// false

array_last() {#collection-method}array_last() {#collection-method}

array_last関数は、テストでパスした最後の配列要素を返します。The array_last function returns the last element of an array passing a given truth test:

$array = [100, 200, 300, 110];

$value = array_last($array, function ($value, $key) {
    return $value >= 150;
});

// 300

array_only() {#collection-method}array_only() {#collection-method}

array_only関数は配列中の指定されたキー/値ペアのアイテムのみを返します。The array_only function will return only the specified key / value pairs from the given array:

$array = ['name' => 'Desk', 'price' => 100, 'orders' => 10];

$array = array_only($array, ['name', 'price']);

// ['name' => 'Desk', 'price' => 100]

array_pluck() {#collection-method}array_pluck() {#collection-method}

array_pluck関数は配列から指定されたキー/値ペアのリストを取得します。The array_pluck function will pluck a list of the given key / value pairs from the array:

$array = [
    ['developer' => ['id' => 1, 'name' => 'Taylor']],
    ['developer' => ['id' => 2, 'name' => 'Abigail']],
];

$array = array_pluck($array, 'developer.name');

// ['Taylor', 'Abigail'];

さらに、結果のリストのキー項目も指定できます。You may also specify how you wish the resulting list to be keyed:

$array = array_pluck($array, 'developer.name', 'developer.id');

// [1 => 'Taylor', 2 => 'Abigail'];

array_prepend() {#collection-method}array_prepend() {#collection-method}

array_prepend関数は配列の先頭にアイテムを追加します。The array_prepend function will push an item onto the beginning of an array:

$array = ['one', 'two', 'three', 'four'];

$array = array_prepend($array, 'zero');

// $array: ['zero', 'one', 'two', 'three', 'four']

array_pull() {#collection-method}array_pull() {#collection-method}

array_pull関数は配列から指定されたキー/値ペアを取得し、同時に削除します。The array_pull function returns and removes a key / value pair from the array:

$array = ['name' => 'Desk', 'price' => 100];

$name = array_pull($array, 'name');

// $name: Desk

// $array: ['price' => 100]

array_set() {#collection-method}array_set() {#collection-method}

array_set関数は「ドット」記法を使用し、深くネストした配列に値をセットします。The array_set function sets a value within a deeply nested array using "dot" notation:

$array = ['products' => ['desk' => ['price' => 100]]];

array_set($array, 'products.desk.price', 200);

// ['products' => ['desk' => ['price' => 200]]]

array_sort() {#collection-method}array_sort() {#collection-method}

array_sort関数は指定されたクロージャの実行結果に基づき、配列をソートします。The array_sort function sorts the array by the results of the given Closure:

$array = [
    ['name' => 'Desk'],
    ['name' => 'Chair'],
];

$array = array_values(array_sort($array, function ($value) {
    return $value['name'];
}));

/*
    [
        ['name' => 'Chair'],
        ['name' => 'Desk'],
    ]
*/

array_sort_recursive() {#collection-method}array_sort_recursive() {#collection-method}

array_sort_recursive関数はsort機能を使い配列を再帰的にソートします。The array_sort_recursive function recursively sorts the array using the sort function:

$array = [
    [
        'Roman',
        'Taylor',
        'Li',
    ],
    [
        'PHP',
        'Ruby',
        'JavaScript',
    ],
];

$array = array_sort_recursive($array);

/*
    [
        [
            'Li',
            'Roman',
            'Taylor',
        ],
        [
            'JavaScript',
            'PHP',
            'Ruby',
        ]
    ];
*/

array_where() {#collection-method}array_where() {#collection-method}

array_whereは指定されたクロージャで、配列をフィルタリングします。The array_where function filters the array using the given Closure:

$array = [100, '200', 300, '400', 500];

$array = array_where($array, function ($value, $key) {
    return is_string($value);
});

// [1 => 200, 3 => 400]

array_wrap() {#collection-method}array_wrap() {#collection-method}

array_wrap関数は、指定した値を配列中にラップします。指定した値が配列中に存在している場合は、変更されません。The array_wrap function will wrap the given value in an array. If the given value is already an array it will not be changed:

$string = 'Laravel';

$array = array_wrap($string);

// [0 => 'Laravel']

head() {#collection-method}head() {#collection-method}

head関数は、配列の最初の要素を返します。The head function returns the first element in the given array:

$array = [100, 200, 300];

$first = head($array);

// 100

last() {#collection-method}last() {#collection-method}

last関数は指定した配列の最後の要素を返します。The last function returns the last element in the given array:

$array = [100, 200, 300];

$last = last($array);

// 300

パスPaths

app_path() {#collection-method}app_path() {#collection-method}

app_path関数は、appディレクトリへの完全パスを取得します。また、app_path関数は、ファイルパスをアプリケーションディレクトリからの相対位置で渡し、完全なパスを生成することもできます。The app_path function returns the fully qualified path to the app directory. You may also use the app_path function to generate a fully qualified path to a file relative to the application directory:

$path = app_path();

$path = app_path('Http/Controllers/Controller.php');

base_path() {#collection-method}base_path() {#collection-method}

base_path関数は、プロジェクトルートの完全パスを返します。base_path関数はさらに、指定されたプロジェクトルートディレクトリからの相対パスから絶対パスを生成します。The base_path function returns the fully qualified path to the project root. You may also use the base_path function to generate a fully qualified path to a given file relative to the project root directory:

$path = base_path();

$path = base_path('vendor/bin');

config_path() {#collection-method}config_path() {#collection-method}

config_path関数はアプリケーション設定ディレクトリの完全パスを返します。The config_path function returns the fully qualified path to the application configuration directory:

$path = config_path();

database_path() {#collection-method}database_path() {#collection-method}

database_path関数はアプリケーションデータベースディレクトリへの完全パスを返します。The database_path function returns the fully qualified path to the application's database directory:

$path = database_path();

mix() {#collection-method}mix() {#collection-method}

mix関数は、バージョンつけしたMixファイルへのパスを返します。The mix function gets the path to a versioned Mix file[/docs/{{version}}/mix]:

mix($file);

public_path() {#collection-method}public_path() {#collection-method}

public_path関数は、publicディレクトリの完全パスを返します。The public_path function returns the fully qualified path to the public directory:

$path = public_path();

resource_path() {#collection-method}resource_path() {#collection-method}

resource_path関数は、resourceディレクトリの完全パスを返します。リソースディレクトリからの相対パスをresource_path関数に指定することで、完全パスを生成することもできます。The resource_path function returns the fully qualified path to the resources directory. You may also use the resource_path function to generate a fully qualified path to a given file relative to the resources directory:

$path = resource_path();

$path = resource_path('assets/sass/app.scss');

storage_path() {#collection-method}storage_path() {#collection-method}

storage_path関数は、storageディレクトリの完全パスを返します。また、storage_path関数は、指定されたstorageディレクトリからの相対ファイルパスから、完全パスを生成します。The storage_path function returns the fully qualified path to the storage directory. You may also use the storage_path function to generate a fully qualified path to a given file relative to the storage directory:

$path = storage_path();

$path = storage_path('app/file.txt');

文字列Strings

camel_case() {#collection-method}camel_case() {#collection-method}

camel_case関数は、文字列をキャメルケース(2つ目以降の単語の先頭は大文字)へ変換します。The camel_case function converts the given string to camelCase:

$camel = camel_case('foo_bar');

// fooBar

class_basename() {#collection-method}class_basename() {#collection-method}

class_basename関数は指定されたクラス名から名前空間を除いた、クラス名だけを取得します。The class_basename returns the class name of the given class with the class' namespace removed:

$class = class_basename('Foo\Bar\Baz');

// Baz

e() {#collection-method}e() {#collection-method}

e関数は、PHPのhtmlspecialchars関数をdouble_encodeオプションにfalseを指定し、実行します。The e function runs PHP's htmlspecialchars function with the double_encode option set to false:

echo e('<html>foo</html>');

// &lt;html&gt;foo&lt;/html&gt;

ends_with() {#collection-method}ends_with() {#collection-method}

ends_with関数は、最初の文字列が2つ目の引数の文字列で終わっているか調べます。The ends_with function determines if the given string ends with the given value:

$value = ends_with('This is my name', 'name');

// true

kebab_case() {#collection-method}kebab_case() {#collection-method}

kebab_case関数は、指定した文字列を「ケバブ-ケース」に変換します。The kebab_case function converts the given string to kebab-case:

$value = kebab_case('fooBar');

// foo-bar

snake_case() {#collection-method}snake_case() {#collection-method}

snake_case関数は文字列をスネークケース(小文字名下線区切り)に変換します。The snake_case function converts the given string to snake_case:

$snake = snake_case('fooBar');

// foo_bar

str_limit() {#collection-method}str_limit() {#collection-method}

str_limit関数は文字列を文字数へ短くします。最初の引数に文字列を受付、最終的な文字列の最大文字数が第2引数です。The str_limit function limits the number of characters in a string. The function accepts a string as its first argument and the maximum number of resulting characters as its second argument:

$value = str_limit('The PHP framework for web artisans.', 7);

// The PHP...

starts_with() {#collection-method}starts_with() {#collection-method}

starts_with関数は指定した文字列が、2番めの文字列で始まっているか調べます。The starts_with function determines if the given string begins with the given value:

$value = starts_with('This is my name', 'This');

// true

str_after() {#collection-method}str_after() {#collection-method}

str_after関数は、指定した値に続く文字列を全て返します。The str_after function returns everything after the given value in a string:

$value = str_after('This is: a test', 'This is:');

// ' a test'

str_contains() {#collection-method}str_contains() {#collection-method}

str_contains関数は指定した文字列が、2つ目の文字列を含んでいるか調べます。The str_contains function determines if the given string contains the given value:

$value = str_contains('This is my name', 'my');

// true

指定した文字列に値のどれかが含まれているかを判定するために、値の配列を渡すことも可能です。You may also pass an array of values to determine if the given string contains any of the values:

$value = str_contains('This is my name', ['my', 'foo']);

// true

str_finish() {#collection-method}str_finish() {#collection-method}

str_finish関数は指定した文字列の最後が、2つ目の引数で終了していない場合、その値を追加します。The str_finish function adds a single instance of the given value to a string if it does not already end with it:

$string = str_finish('this/string', '/');
$string2 = str_finish('this/string/', '/');

// this/string/

str_is() {#collection-method}str_is() {#collection-method}

str_is関数は指定した文字列がパターンに一致しているかを判定します。アスタリスクが使用されるとワイルドカードとして利用されます。The str_is function determines if a given string matches a given pattern. Asterisks may be used to indicate wildcards:

$value = str_is('foo*', 'foobar');

// true

$value = str_is('baz*', 'foobar');

// false

str_plural() {#collection-method}str_plural() {#collection-method}

str_plural関数は単数形を複数形へ変換します。この関数は現在英語のみサポートしています。The str_plural function converts a string to its plural form. This function currently only supports the English language:

$plural = str_plural('car');

// cars

$plural = str_plural('child');

// children

整数をこの関数の第2引数に指定することで、文字列の単数形と複数形を切り替えて取得できます。You may provide an integer as a second argument to the function to retrieve the singular or plural form of the string:

$plural = str_plural('child', 2);

// children

$plural = str_plural('child', 1);

// child

str_random() {#collection-method}str_random() {#collection-method}

str_random関数は指定された長さのランダムな文字列を生成します。この関数は、PHPのrandom_bytes関数を使用します。The str_random function generates a random string of the specified length. This function uses PHP's random_bytes function:

$string = str_random(40);

str_singular() {#collection-method}str_singular() {#collection-method}

str_singular関数は複数形を単数形へ変換します。この関数は、現在英語のみサポートしています。The str_singular function converts a string to its singular form. This function currently only supports the English language:

$singular = str_singular('cars');

// car

str_slug() {#collection-method}str_slug() {#collection-method}

str_slug関数は指定された文字列から、URLフレンドリーな「スラグ」を生成します。The str_slug function generates a URL friendly "slug" from the given string:

$title = str_slug('Laravel 5 Framework', '-');

// laravel-5-framework

studly_case() {#collection-method}studly_case() {#collection-method}

studly_case関数は文字列をアッパーキャメルケース(単語の頭文字を大文字)に変換します。The studly_case function converts the given string to StudlyCase:

$value = studly_case('foo_bar');

// FooBar

title_case() {#collection-method}title_case() {#collection-method}

title_case関数は、指定された文字列を「タイトルケース」へ変換します。The title_case function converts the given string to Title Case:

$title = title_case('a nice title uses the correct case');

// A Nice Title Uses The Correct Case

trans() {#collection-method}trans() {#collection-method}

trans関数は指定した言語行を言語ファイルを使用して翻訳します。The trans function translates the given language line using your localization files[/docs/{{version}}/localization]:

echo trans('validation.required'):

trans_choice() {#collection-method}trans_choice() {#collection-method}

trans_choice関数は指定された言語行を数値をもとに翻訳します。Lang::choiceのエイリアスです。The trans_choice function translates the given language line with inflection:

$value = trans_choice('foo.bar', $count);

URLURLs

action() {#collection-method}action() {#collection-method}

action関数は指定されたコントローラアクションからURLを生成します。完全修飾コントローラー名は必要ありません。代わりにApp\Http\Controllers名前空間からの相対クラス名を指定してください。The action function generates a URL for the given controller action. You do not need to pass the full namespace to the controller. Instead, pass the controller class name relative to the App\Http\Controllers namespace:

$url = action('HomeController@getIndex');

メソッドがルートパラメーターを受け付ける場合は、第2引数で指定してください。If the method accepts route parameters, you may pass them as the second argument to the method:

$url = action('UserController@profile', ['id' => 1]);

asset() {#collection-method}asset() {#collection-method}

現在のリクエストのスキーマ(HTTPかHTTPS)を使い、アセットへのURLを生成します。Generate a URL for an asset using the current scheme of the request (HTTP or HTTPS):

$url = asset('img/photo.jpg');

secure_asset() {#collection-method}secure_asset() {#collection-method}

HTTPSを使い、アセットへのURLを生成します。Generate a URL for an asset using HTTPS:

echo secure_asset('foo/bar.zip', $title, $attributes = []);

route() {#collection-method}route() {#collection-method}

route関数は指定された名前付きルートへのURLを生成します。The route function generates a URL for the given named route:

$url = route('routeName');

ルートにパラメーターを受け付ける場合は第2引数で指定しますIf the route accepts parameters, you may pass them as the second argument to the method:

$url = route('routeName', ['id' => 1]);

route関数はデフォルトとして絶対URLを生成します。相対URLを生成したい場合は、第3引数にfalseを渡してください。By default, the route function generates an absolute URL. If you wish to generate a relative URL, you may pass false as the third parameter:

$url = route('routeName', ['id' => 1], false);

secure_url() {#collection-method}secure_url() {#collection-method}

secure_url関数は、指定したパスへの完全なHTTPS URLを生成します。The secure_url function generates a fully qualified HTTPS URL to the given path:

echo secure_url('user/profile');

echo secure_url('user/profile', [1]);

url() {#collection-method}url() {#collection-method}

url関数は指定したパスへの完全なURLを生成します。The url function generates a fully qualified URL to the given path:

echo url('user/profile');

echo url('user/profile', [1]);

パスを指定しない場合は、Illuminate\Routing\UrlGeneratorインスタンスを返します。If no path is provided, a Illuminate\Routing\UrlGenerator instance is returned:

echo url()->current();
echo url()->full();
echo url()->previous();

その他Miscellaneous

abort() {#collection-method}abort() {#collection-method}

abort関数は、例外ハンドラによりレンダーされるであろう、HTTP例外を投げます。The abort function throws a HTTP exception which will be rendered by the exception handler:

abort(401);

例外のレスポンステキストを指定することもできます。You may also provide the exception's response text:

abort(401, 'Unauthorized.');

abort_if() {#collection-method}abort_if() {#collection-method}

abort_if関数は、指定された論理値がtrueと評価された場合に、HTTP例外を投げます。The abort_if function throws an HTTP exception if a given boolean expression evaluates to true:

abort_if(! Auth::user()->isAdmin(), 403);

abort_unless() {#collection-method}abort_unless() {#collection-method}

abort_unless関数は、指定した論理値がfalseと評価された場合に、HTTP例外を投げます。The abort_unless function throws an HTTP exception if a given boolean expression evaluates to false:

abort_unless(Auth::user()->isAdmin(), 403);

auth() {#collection-method}auth() {#collection-method}

auth関数はAuthenticatorインスタンスを返します。Authファサードの代わりに便利に使用できます。The auth function returns an authenticator instance. You may use it instead of the Auth facade for convenience:

$user = auth()->user();

back() {#collection-method}back() {#collection-method}

back関数はユーザーの直前のロケーションへのリダイレクトレスポンスを生成します。The back() function generates a redirect response to the user's previous location:

return back();

bcrypt() {#collection-method}bcrypt() {#collection-method}

bcrypt関数は指定した値をBcryptを使用しハッシュ化します。Hashファサードの代用として便利に使用できます。The bcrypt function hashes the given value using Bcrypt. You may use it as an alternative to the Hash facade:

$password = bcrypt('my-secret-password');

cache() {#collection-method}cache() {#collection-method}

cache関数はキャッシュから値を取得するために使用します。キャッシュに指定したキーが存在しない場合、オプション値が返されます。The cache function may be used to get values from the cache. If the given key does not exist in the cache, an optional default value will be returned:

$value = cache('key');

$value = cache('key', 'default');

関数にキー/値ペアの配列を渡すと、アイテムをキャッシュへ追加します。さらに分数、もしくはキャッシュ値が有効であると推定される期限を渡すこともできます。You may add items to the cache by passing an array of key / value pairs to the function. You should also pass the number of minutes or duration the cached value should be considered valid:

cache(['key' => 'value'], 5);

cache(['key' => 'value'], Carbon::now()->addSeconds(10));

collect() {#collection-method}collect() {#collection-method}

collect関数は指定したアイテムから、コレクションインスタンスを生成します。The collect function creates a collection[/docs/{{version}}/collections] instance from the given array:

$collection = collect(['taylor', 'abigail']);

config() {#collection-method}config() {#collection-method}

config関数は設定変数の値を取得します。設定値はファイル名とアクセスしたいオプションを「ドット」記法で指定します。デフォルト値が指定でき、設定オプションが存在しない時に返されます。The config function gets the value of a configuration variable. The configuration values may be accessed using "dot" syntax, which includes the name of the file and the option you wish to access. A default value may be specified and is returned if the configuration option does not exist:

$value = config('app.timezone');

$value = config('app.timezone', $default);

configヘルパにキー/値ペアの配列を渡せば、実行時の設定変数をセットすることもできます。The config helper may also be used to set configuration variables at runtime by passing an array of key / value pairs:

config(['app.debug' => true]);

csrf_field() {#collection-method}csrf_field() {#collection-method}

csrf_field関数は、CSRFトークン値を持つHTML「隠し」入力フィールドを生成します。ブレード記法を使用した例です。The csrf_field function generates an HTML hidden input field containing the value of the CSRF token. For example, using Blade syntax[/docs/{{version}}/blade]:

{{ csrf_field() }}

csrf_token() {#collection-method}csrf_token() {#collection-method}

csrf_field関数は、CSRFトークン値を持つHTML「隠し」入力フィールドを生成します。ブレード記法を使用した例です。The csrf_token function retrieves the value of the current CSRF token:

$token = csrf_token();

dd() {#collection-method}dd() {#collection-method}

dd関数は指定された変数の内容を表示し、スクリプトの実行を停止します。The dd function dumps the given variables and ends execution of the script:

dd($value);

dd($value1, $value2, $value3, ...);

スクリプトの実行を停止したくない場合は、代わりにdump関数を使ってください。If you do not want to halt the execution of your script, use the dump function instead:

dump($value);

dispatch() {#collection-method}dispatch() {#collection-method}

dispatch関数は、Laravelのジョブキューへ、新しいジョブを投入します。The dispatch function pushes a new job onto the Laravel job queue[/docs/{{version}}/queues]:

dispatch(new App\Jobs\SendEmails);

env() {#collection-method}env() {#collection-method}

env関数は環境変数の値を取得します。取得できない場合はデフォルト値を返します。The env function gets the value of an environment variable or returns a default value:

$env = env('APP_ENV');

// 変数が存在しない場合にデフォルト値を返す
$env = env('APP_ENV', 'production');

event() {#collection-method}event() {#collection-method}

event関数は指定したイベントをリスナに対して発行しますThe event function dispatches the given event[/docs/{{version}}/events] to its listeners:

event(new UserRegistered($user));

factory() {#collection-method}factory() {#collection-method}

factory関数は指定したクラス、名前、個数のモデルファクトリビルダを生成します。これはテストシーディング(DB初期値設定)で使用できます。The factory function creates a model factory builder for a given class, name, and amount. It can be used while testing[/docs/{{version}}/database-testing#writing-factories] or seeding[/docs/{{version}}/seeding#using-model-factories]:

$user = factory(App\User::class)->make();

info() {#collection-method}info() {#collection-method}

info関数はログへ情報(information)を書き出します。The info function will write information to the log:

info('Some helpful information!');

関連情報の配列を関数へ渡すこともできます。An array of contextual data may also be passed to the function:

info('User login attempt failed.', ['id' => $user->id]);

logger() {#collection-method}logger() {#collection-method}

logger関数は、debugレベルのメッセージをログへ書き出します。The logger function can be used to write a debug level message to the log:

logger('Debug message');

関連情報の配列を関数へ渡すこともできます。An array of contextual data may also be passed to the function:

logger('User has logged in.', ['id' => $user->id]);

関数に値を渡さない場合は、ロガーインスタンスが返されます。A logger[/docs/{{version}}/errors#logging] instance will be returned if no value is passed to the function:

logger()->error('You are not allowed here.');

method_field() {#collection-method}method_field() {#collection-method}

method_field関数はフォームのHTTP動詞の見せかけの値を保持する「隠し」HTTP入力フィールドを生成します。Blade記法を使う例です。The method_field function generates an HTML hidden input field containing the spoofed value of the form's HTTP verb. For example, using Blade syntax[/docs/{{version}}/blade]:

<form method="POST">
    {{ method_field('DELETE') }}
</form>

old() {#collection-method}old() {#collection-method}

old関数はセッションにフラッシュデーターとして保存されている直前の入力値を取得します。The old function retrieves[/docs/{{version}}/requests#retrieving-input] an old input value flashed into the session:

$value = old('value');

$value = old('value', 'default');

redirect() {#collection-method}redirect() {#collection-method}

redirect関数は、リダイレクトHTTPレスポンスを返します。引数無しで呼び出した場合は、リダイレクタインスタンスを返します。The redirect function returns a redirect HTTP response, or returns the redirector instance if called with no arguments:

return redirect('/home');

return redirect()->route('route.name');

request() {#collection-method}request() {#collection-method}

request関数は現在のリクエストインスタンスを返すか、入力アイテムを取得します。The request function returns the current request[/docs/{{version}}/requests] instance or obtains an input item:

$request = request();

$value = request('key', $default = null)

response() {#collection-method}response() {#collection-method}

response関数はresponseインスタンスを返すか、レスポンスファクトリのインスタンスを取得します。The response function creates a response[/docs/{{version}}/responses] instance or obtains an instance of the response factory:

return response('Hello World', 200, $headers);

return response()->json(['foo' => 'bar'], 200, $headers);

retry() {#collection-method}retry() {#collection-method}

retry関数は指定された最大試行回数をすぎるまで、指定されたコールバックを実行します。コールバックが例外を投げなければ、返却値が返されます。コールバックが例外を投げた場合は、自動的にリトライされます。最大試行回数を超えると、例外が投げられます。The retry function attempts to execute the given callback until the given maximum attempt threshold is met. If the callback does not throw an exception, it's return value will be returned. If the callback throws an exception, it will automatically be retried. If the maximum attempt count is exceeded, the exception will be thrown:

return retry(5, function () {
    // 実行間で500ms空け、5回試行する
}, 100);

session() {#collection-method}session() {#collection-method}

session関数はセッションへ値を設定、もしくは取得するために使用します。The session function may be used to get or set session values:

$value = session('key');

キー/値ペアの配列を渡し、値を設定することができます。You may set values by passing an array of key / value pairs to the function:

session(['chairs' => 7, 'instruments' => 3]);

関数に引数を渡さない場合は、セッション保存域が返されます。The session store will be returned if no value is passed to the function:

$value = session()->get('key');

session()->put('key', $value);

value() {#collection-method}value() {#collection-method}

value関数は値が指定された場合は、シンプルにその値を返します。しかし「クロージャ」が関数に渡されると、そのクロージャを実行し結果を返します。The value function's behavior will simply return the value it is given. However, if you pass a Closure to the function, the Closure will be executed then its result will be returned:

$value = value(function () {
    return 'bar';
});

view() {#collection-method}view() {#collection-method}

view関数はviewインスタンスを返します。The view function retrieves a view[/docs/{{version}}/views] instance:

return view('auth.login');

章選択

公式パッケージ

設定

明暗テーマ
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に保存してある設定項目をすべて削除し、デフォルト状態へ戻します。

ヘッダー項目移動

キーボード操作