Readouble

Laravel 6.x HTTPリダイレクト

リダイレクトの作成Creating Redirects

リダイレクトレスポンスは、Illuminate\Http\RedirectResponseクラスのインスタンスで、ユーザーを他のURLへリダイレクトするために必要なしっかりとしたヘッダを含んでいる必要があります。RedirectResponseインスタンスを生成する方法はいくつかあります。一番簡単なのは、グローバルなredirectヘルパを使用する方法です。Redirect responses are instances of the Illuminate\Http\RedirectResponse class, and contain the proper headers needed to redirect the user to another URL. There are several ways to generate a RedirectResponse instance. The simplest method is to use the global redirect helper:

Route::get('dashboard', function () {
    return redirect('home/dashboard');
});

無効なフォームが送信された場合など、まれにユーザーを直前のページへリダイレクトする必要が起きます。グローバルなbackヘルパ関数を使用することで行なえます。この機能はセッションを利用しているため、back関数を呼び出すルートがwebミドルウェアグループを使用しているか、全セッションミドルウェアを確実に適用してください。Sometimes you may wish to redirect the user to their previous location, such as when a submitted form is invalid. You may do so by using the global back helper function. Since this feature utilizes the session[/docs/{{version}}/session], make sure the route calling the back function is using the web middleware group or has all of the session middleware applied:

Route::post('user/profile', function () {
    // リクエスのバリデート処理…

    return back()->withInput();
});

名前付きルートへのリダイレクトRedirecting To Named Routes

redirectヘルパを引数なしで呼び出すと、Illuminate\Routing\Redirectorインスタンスが返されるため、Redirectorインスタンスの全メソッドを呼び出せます。たとえば、名前付きルートへのRedirectResponseを生成する場合は、routeメソッドを使用できます。When you call the redirect helper with no parameters, an instance of Illuminate\Routing\Redirector is returned, allowing you to call any method on the Redirector instance. For example, to generate a RedirectResponse to a named route, you may use the route method:

return redirect()->route('login');

ルートにパラメータが必要な場合は、routeメソッドの第2引数として渡してください。If your route has parameters, you may pass them as the second argument to the route method:

// profile/{id}ルートへのリダイレクト

return redirect()->route('profile', ['id' => 1]);

Eloquentモデルを使用したパラメータの埋め込みPopulating Parameters Via Eloquent Models

あるEloquentモデルの"ID"パラメータを含むルートへリダイレクトする場合は、そのモデル自身を渡してください。IDは自動的に取り出されます。If you are redirecting to a route with an "ID" parameter that is being populated from an Eloquent model, you may pass the model itself. The ID will be extracted automatically:

// profile/{id}ルートへのリダイレクト

return redirect()->route('profile', [$user]);

ルートパラメータへ含める値をカスタマイズしたい場合は、EloquentモデルのgetRouteKeyメソッドをオーバーライドしてください。If you would like to customize the value that is placed in the route parameter, you should override the getRouteKey method on your Eloquent model:

/**
 * モデルのルートキー値の取得
 *
 * @return mixed
 */
public function getRouteKey()
{
    return $this->slug;
}

コントローラアクションへのリダイレクトRedirecting To Controller Actions

コントローラアクションへのリダイレクトを生成することもできます。そのためには、actionメソッドへコントローラとアクションの名前を渡してください。LaravelのRouteServiceProviderでベースのコントローラ名前空間が指定されているため、コントローラへの完全な空間名を指定する必要はないことを覚えておきましょう。You may also generate redirects to controller actions[/docs/{{version}}/controllers]. To do so, pass the controller and action name to the action method. Remember, you do not need to specify the full namespace to the controller since Laravel's RouteServiceProvider will automatically set the base controller namespace:

return redirect()->action('HomeController@index');

コントローラルートがパラメータを必要としている場合、actionメソッドの第2引数として渡してください。If your controller route requires parameters, you may pass them as the second argument to the action method:

return redirect()->action(
    'UserController@profile', ['id' => 1]
);

フラッシュセッションデータを伴うリダイレクトRedirecting With Flashed Session Data

新しいURLへリダイレクトし、セッションへデータを保持するのは、通常同時に行います。あるアクションが正しく実行された後に、セッションへ成功メッセージをフラッシュデータとして保存するのが典型的なケースでしょう。便利なように、RedirectResponseインスタンスを生成し、データをセッションへフラッシュデータとして保存するには、記述的なチェーン一つで行なえます。Redirecting to a new URL and flashing data to the session[/docs/{{version}}/session#flash-data] are usually done at the same time. Typically, this is done after successfully performing an action when you flash a success message to the session. For convenience, you may create a RedirectResponse instance and flash data to the session in a single, fluent method chain:

Route::post('user/profile', function () {
    // ユーザープロフィールの更新処理…

    return redirect('dashboard')->with('status', 'プロフィールを更新しました!');
});

ユーザーをリダイレクトしたあと、セッションのフラッシュデータとして保存したメッセージを表示できます。例としてBlade記法を使ってみます。After the user is redirected, you may display the flashed message from the session[/docs/{{version}}/session]. For example, using Blade syntax[/docs/{{version}}/blade]:

@if (session('status'))
    <div class="alert alert-success">
        {{ session('status') }}
    </div>
@endif

章選択

設定

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

ヘッダー項目移動

キーボード操作