LoginSignup
0
0

More than 1 year has passed since last update.

認証ディレクティブ

Posted at

ログイン

@authを使用する事でユーザーがログイン済みの際にページ内で、表示させる項目やメニューを設定する事ができます。

<実際の使用例>

home.blade.php
      @auth
      <li>{{ Auth::user()->name  }}</li>
      <li><a href="{{ route('profile.edit') }}">プロフィール編集</a></li>
      <li><a href="{{ route('photo.create') }}">画像登録</a></li>
      <li><a href="{{ route('follow.list') }}">フォローリスト</a></li>
      <li><button form="logout-button" type="submit">ログアウト</button></li>
      <form id="logout-button" action="{{ route('logout') }}" method="POST">
        @csrf
      </form>
      @endauth

このように@auth@endauthで囲む事で使用する事ができます。

非ログイン

@guestを使用する事で非ログイン時にページ内で、表示させる項目やメニューを設定する事ができます。

<実際の使用例>

home.blade.php
      @guest
      <li><a href="{{ route('home') }}">ホーム</a></li>
      <li><a href="{{ route('timeline') }}">タイムライン</a></li>
      <li><a href="{{ route('trend') }}">トレンド</a></li>
      <li><a href="{{ route('login') }}">ログイン</a></li>
      @endguest

このように@guest@endguestで囲む事で使用する事ができます。

認証ディレクティブ下記参照用

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