Readouble

Laravel 5.0 Session

Configuration

Since HTTP driven applications are stateless, sessions provide a way to store information about the user across requests. Laravel ships with a variety of session back-ends available for use through a clean, unified API. Support for popular back-ends such as Memcached, Redis, and databases is included out of the box.

The session configuration is stored in config/session.php. Be sure to review the well documented options available to you in this file. By default, Laravel is configured to use the file session driver, which will work well for the majority of applications.

Before using Redis sessions with Laravel, you will need to install the predis/predis package (~1.0) via Composer.

Note: If you need all stored session data to be encrypted, set the encrypt configuration option to true.

Note: When using the cookie session driver, you should never remove the EncryptCookie middleware from your HTTP kernel. If you remove this middleware, your application will be vulnerable to remote code injection.

Reserved Keys

The Laravel framework uses the flash session key internally, so you should not add an item to the session by that name.

Session Usage

The session may be accessed in several ways, via the HTTP request's session method, the Session facade, or the session helper function. When the session helper is called without arguments, it will return the entire session object. For example:

session()->regenerate();

Storing An Item In The Session

Session::put('key', 'value');

session(['key' => 'value']);

Push A Value Onto An Array Session Value

Session::push('user.teams', 'developers');

Retrieving An Item From The Session

$value = Session::get('key');

$value = session('key');

Retrieving An Item Or Returning A Default Value

$value = Session::get('key', 'default');

$value = Session::get('key', function() { return 'default'; });

Retrieving An Item And Forgetting It

$value = Session::pull('key', 'default');

Retrieving All Data From The Session

$data = Session::all();

Determining If An Item Exists In The Session

if (Session::has('users'))
{
	//
}

Removing An Item From The Session

Session::forget('key');

Removing All Items From The Session

Session::flush();

Regenerating The Session ID

Session::regenerate();

Flash Data

Sometimes you may wish to store items in the session only for the next request. You may do so using the Session::flash method:

Session::flash('key', 'value');

Reflashing The Current Flash Data For Another Request

Session::reflash();

Reflashing Only A Subset Of Flash Data

Session::keep(['username', 'email']);

Database Sessions

When using the database session driver, you will need to setup a table to contain the session items. Below is an example Schema declaration for the table:

Schema::create('sessions', function($table)
{
	$table->string('id')->unique();
	$table->text('payload');
	$table->integer('last_activity');
});

Of course, you may use the session:table Artisan command to generate this migration for you!

php artisan session:table

composer dump-autoload

php artisan migrate

Session Drivers

The session "driver" defines where session data will be stored for each request. Laravel ships with several great drivers out of the box:

  • file - sessions will be stored in storage/framework/sessions.
  • cookie - sessions will be stored in secure, encrypted cookies.
  • database - sessions will be stored in a database used by your application.
  • memcached / redis - sessions will be stored in one of these fast, cached based stores.
  • array - sessions will be stored in a simple PHP array and will not be persisted across requests.

Note: The array driver is typically used for running unit tests, so no session data will be persisted.

章選択

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

ヘッダー項目移動

キーボード操作