不同授权策略类中的相同方法, 框架是怎么识别的呢?
@can('destroy', $status)
<form action="{{ route('statuses.destroy', $status->id) }}" method="POST">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<button type="submit" class="btn btn-sm btn-danger">删除</button>
</form>
@endcan
上面的destroy方法, 在UserPolicy.php 和 StatusPolicy.php中都有这个方法, 上面这段代码中, 框架是怎么知道应该使用StatusPolicy中的destroy方法呢?
关于 LearnKu
:confused:
同问,没人给解答一下吗?
@friendOfTime

这是AuthServiceProvider.php
如果上面定义了对应关系,就直接用。
没有定义的话,下面boot里可以自己猜。
can() 方法会根据第二个参数的模型的类型去授权策略注册表里面去查找该模型对应的授权策略类
用户授权《Laravel 5.5 中文文档》