1
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?

Laravel Bladeでauth画面 + ログイン前 のフッターを作成・表示する方法

Last updated at Posted at 2025-05-12

この記事でできること

・トップ画面(ログイン前)と、ログイン・新規登録画面(auth全般)で異なるフッターを出し分ける方法。
・Bladeコンポーネントを用途別に作り分けるシンプルな実装手順。

トップ画面
スクリーンショット 2025-05-12 11.49.53.png

auth画面
スクリーンショット 2025-05-12 11.49.26.png

手順(トップ画面の場合)

① コンポーネントファイルを作成

php artisan make:component FooterTop

作成されるファイル:
・app/View/Components/FooterTop.php
・resources/views/components/footer-top.blade.php

② footer-top.blade.php にHTMLを書く

/views/components/footer-top.blade.php
<footer class="shadow bg-gray-200 py-4 text-center text-sm text-gray-500 w-full">
    &copy;
    <span class="ml-1">{{ date('Y') }}</span>
    <span class="ml-1">{{ config('app.name') }}</span>
    <span class="ml-1">All rights reserved</span>
</footer>

③ フッターを呼び出すレイアウトに x-footer-top を追加

・ x-footer-top を追記
・ body、main の class も適宜修正

/views/welcome.blade.php
<body class="min-h-screen flex flex-col font-sans antialiased items-center justify-center bg-gray-100">
    <main class="flex-grow flex flex-col items-center justify-center text-center">

    <!-- コンテンツをここに -->
        
    </main>

    <x-footer-top />
</body>

ゴール

スクリーンショット 2025-05-12 13.00.12.png

手順(auth画面の場合)

① コンポーネントファイルを作成

php artisan make:component FooterAuth

作成されるファイル:
・app/View/Components/FooterAuth.php
・resources/views/components/footer-auth.blade.php

② footer-auth.blade.php にHTMLを書く

/views/components/footer-auth.blade.php
<footer class="shadow bg-gray-200 py-4 text-center text-sm text-gray-500 w-full">
    &copy;
    <span class="ml-1">{{ date('Y') }}</span>
    <span class="ml-1">{{ config('app.name') }}</span>
    <span class="ml-1">All rights reserved</span>
</footer>

③ フッターを呼び出すレイアウトに x-footer-auth を追加

以下コードに全体を修正

/views/layouts/guest.blade.php
<body class="font-sans text-gray-900 antialiased min-h-screen flex flex-col bg-gray-100">
    <div class="flex-grow flex flex-col justify-center">
        <div class="flex justify-center">
            <a href="/">
                <x-application-logo class="w-20 h-20 fill-current text-gray-500" />
            </a>
        </div>
    
        <div class="w-full sm:max-w-md md:max-w-lg lg:max-w-xl xl:max-w-2xl mx-auto mt-6 px-6 py-4 bg-white shadow-md overflow-hidden sm:rounded-lg">
            {{ $slot }}
        </div>
    </div>
    
    <x-footer-auth />
</body>

ゴール

スクリーンショット 2025-05-12 13.15.49.png

関連:footer を共通化して作成・表示する手順【Laravel9】

1
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
1
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?