首页 > 解决方案 > 如何使用一个视图和多个守卫 Laravel

问题描述

我的系统中有多个警卫

Admin
User

管理员和用户都可以添加组织详细信息,但它们具有不同的模板布局。我现在在做什么我像这样创建每个警卫的视图

views
  user
    organizations
       index.blade.php
       _form.blade.php
       create.blade.php
       edit.blade.php
  admin
    organizations
       index.blade.php
       _form.blade.php
       create.blade.php
       edit.blade.php

现在我想创建一个视图,可供具有不同布局的多个警卫使用

views
   organizations
      index.blade.php
      _form.blade.php
      create.blade.php
      edit.blade.php

标签: laravellaravel-5laravel-6laravel-7laravel-views

解决方案


来自Laravel Blade 文档

如果需要,您可以指定在使用 @auth 和 @guest 指令时应检查的身份验证保护:

@auth('admin')
    // The user is authenticated...
@endauth

@guest('admin')
    // The user is not authenticated...
@endguest

推荐阅读