1 回答
TA贡献1872条经验 获得超3个赞
将此功能添加到检查用户角色的用户模型中:
/**
* Check if this user belongs to a role
*
* @return bool
*/
public function hasRole($role_name)
{
foreach ($this->roles as $role){
//I assumed the column which holds the role name is called role_name
if ($role->role_name == $role_name)
return true;
}
return false;
}
现在在您看来,您可以这样称呼它:
<select class="col-12 border mt-2 pt-2" name="indicator_id">
@foreach($indicators as $indicator)
@if (Auth::user()->hasRole('Secretary'))
<option value="{{ $indicator->id }}">{{ $indicator->name }}</option>
@elseif (!Auth::user()->hasRole('Secretary') && {{ $indicator->name }} == 'internalLetter')
<option value="{{ $indicator->id }}">Internal Letter</option>
@endif
@endforeach
</select>
- 1 回答
- 0 关注
- 87 浏览
添加回答
举报