我在我的laravel项目中安装Auth。在我的用户表中,我为定义教师和学生定义了一个角色列。所以在我的刀片页面中,我想为老师提供访问权限,并为学生隐藏该部分。但我不能这样做。 这是我的代码:这部分仅供老师使用。
@if($user->role==Teacher)
<div class="">
<div class="">
<div class="col-md-7 col-md-offset-3">
{!! Form::open(['files'=>true])!!}
<div class="panel panel-default">
<div class="panel-heading">Submit your works</div>
<div class="panel-body">
<div class="form-group>">
<label>Write a new title</label>
<textarea class="form-control" name="assainments" id="assainments"></textarea>
</div>
</div>
<div class="panel-footer clearfix">
<div class="row">
<div class="col-md-6">
<label for="file-upload" class="custom-file-upload">
<i class="glyphicon glyphicon-paperclip"></i>
</label>
<input id="file-upload" name="status_file_upload" type="file"/>
</div>
<div class="col-md-6">
<button class="btn btn-info pull-right btn-am"><i class="fa fa-plus">Add works</i></button>
</div>
</div>
</div>
</div>
@endif
答案 0 :(得分:1)
使用$ user in your view you need to pass it from the controller or the method from which you are calling the view.<br/>
Or instead of
$ user you can use
Auth :: user()`:
@if(Auth::user()->role==Teacher)