0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravelでフラッシュメッセージを表示したい。

Last updated at Posted at 2021-09-08

View

sessionメッセージがあれば、表示する記述を追加する。

blade.php
    @if (session('flash_message'))
        <div class="flash_message">
            {{ session('flash_message') }}
        </div>
    @endif
app_blade.php
<body>
    <div id="app">

        @yield('header')
        @yield('dheader')

        <main class="py-4">
          
// @yield('content')の上くらいに入れるのがちょうどいい。
            @if (session('flash_message'))
              <div class="flash_message">
                  {{ session('flash_message') }}
              </div>
            @endif

            @yield('content')
            @yield('inc_pagination')

            <section id="dashboard">
                @yield('dsidebar')
                @yield('dashboard')
            </section>
        </main>
    </div>

    @yield('footer')
</body>

Controller

if文などで、分岐を作り、withでフラッシュメッセージをViewへ送る。

Controller.php

return redirect()->back()->with('flash_message', '登録が完了しました。');

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?