1 回答

TA貢獻1872條經驗 獲得超4個贊
將此功能添加到檢查用戶角色的用戶模型中:
/**
* 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 關注
- 112 瀏覽
添加回答
舉報