Laravel/blade 有条件的组件
Laravel/blade component with conditions
有什么方法可以在组件上使用类似于 @can('update', $project)
的东西吗?
以下无效;
<x-input @cannot('update', $project) disabled="disabled" @endcannot />
我做不到;
<x-input :disabled="@cannot('update', $project)" />
在组件中获取 true
/false
值。
为什么不用
@can('update', $project)
<x-input />
@endcan
我会添加 disabled
到你组件的 props
@props(['disabled' => false])
<input
@if($disabled) disabled @endif
{{ $attributes }}
/>
那就这样用吧
<x-input :disabled="Auth::user()->cannot('update', $project)" />
有什么方法可以在组件上使用类似于 @can('update', $project)
的东西吗?
以下无效;
<x-input @cannot('update', $project) disabled="disabled" @endcannot />
我做不到;
<x-input :disabled="@cannot('update', $project)" />
在组件中获取 true
/false
值。
为什么不用
@can('update', $project)
<x-input />
@endcan
我会添加 disabled
到你组件的 props
@props(['disabled' => false])
<input
@if($disabled) disabled @endif
{{ $attributes }}
/>
那就这样用吧
<x-input :disabled="Auth::user()->cannot('update', $project)" />