laravel - 使用自动绑定时策略类中的字符串或对象?
问题描述
我正在使用 Laravel 8。
我有这条路线:
Route::resource('organizations/{organization}/users/{user}/alerts', AlertController::class)->whereUuid(['organization', 'user', 'alert'])->scoped();
我像这样管理控制器中的策略:
public function __construct() {
$this->organization = request()->route()->parameter('organization');
$this->user = request()->route()->parameter('user');
$this->alert = request()->route()->parameter('alert');
Log::info($this->organization);
Log::info($this->user);
Log::info($this->alert);
$this->authorizeResource(Alert::class);
}
如您所见,有一些调试行。在这一步中,所有路由参数都可以:我为每个参数设置了一个 uuid。
在策略类中:
public function __construct()
{
$this->organization = request()->route()->parameter('organization');
$this->user = request()->route()->parameter('user');
$this->alert = request()->route()->parameter('alert');
}
public function before(User $user)
{
if ($user->role_id === 'SUPERADMIN') {
return true;
}
Log::info($this->organization);
Log::info($this->user);
Log::info($this->alert);
if ($user->organization_id !== $this->organization->id) {
return false;
}
}
相同的调试行显示“组织”和“用户”的 uuid(字符串)。但“警报”的对象。
在这个策略类中,我必须拥有什么样的 var?字符串或相对于字符串的对象?
解决方案
推荐阅读
- javascript - 是否可以从 socket.io 客户端获取对服务器的请求中删除 sid?
- r - 如何更改 POSIXct 对象在构面标题中的显示?
- mongodb - 如何导入 go 的 mongo-driver bson
- assembly - 汇编指令中的esi0a是什么意思?
- javascript - 有没有办法将 CSS-transform 应用于在 mousemove 上被 CSS-transformed 的元素内部的元素?
- javascript - Uncaught TypeError: a.indexOf is not a function [PRELOADER]
- excel - 为什么 IsDate 不能按预期工作?以及如何获取列中下一个单元格的日期值?
- django - 如何为数据库拉取和操作构建视图
- c - 将新工作人员添加到列表中,但保持按名称排序
- sql-server - 是否有使用 SQL 查询语句从物理列创建逻辑列的最佳方法?