来自Blade引擎的@cannot语句不起作用

问题描述 投票:0回答:2

我正在尝试在我的模板中使用@cannot,但我有以下问题。随着代码:

@section('content')
    @can('upload-images',$flyer)
        <form action="{{ URL::to('/') }}/{{ $flyer->zip }}/{{ $flyer->street }}/photos" method="POST" class="dropzone" enctype="multipart/form-data">
            {{ csrf_field() }}
        </form>
    @endcan
    @cannot
        <p>Not allowed</p>
    @endcannot
@stop

@cannot抛出以下错误:

Undefined class constant 'denies'

我知道@cannot存在并且还使用Gate :: denies,这是我正在采取的错误,这里是Github提交,其中应该发生魔法:

https://github.com/laravel/framework/commit/9c41aa0d53412e3008285e89ff9764fa51b42469

有线索吗?谢谢!

laravel-5 blade
2个回答
0
投票

Laravel的文档正在更新。我应该使用@else:

@can(...)
@else
@endcan

@cannot应该用作@can的反面,但不能同时使用:

@cannot(...)
@else
@endcannot

0
投票

您忘记了cannot方法中的输入:

@cannot('upload-images',$flyer)
       <p>Not allowed</p>
@endcannot

但是在这种情况下使用其他更优雅

 @can('upload-images',$flyer)
        <form action="{{ URL::to('/') }}/{{ $flyer->zip }}/{{ $flyer->street }}/photos" method="POST" class="dropzone" enctype="multipart/form-data">
            {{ csrf_field() }}
        </form>
 @else
        <p>Not allowed</p>
 @endcan
© www.soinside.com 2019 - 2024. All rights reserved.