laravel显示按钮基于经过身份验证的用户

时间:2018-09-13 03:17:13

标签: php laravel laravel-blade

如果用户已通过身份验证且ID等于subject_id,我如何显示按钮,我已经使用了与表和模型的关系,我只需要使此工作有效即可。

控制器:

$subjects =Subject::with('user')->findorFail($id);

查看刀片:

@if($subjects == Auth::user())
<input style="text-align: center;border-radius:5px;"  type="submit"value="SUBMIT" class="btn btn-danger btn-sm"> @else<p>View Mode</p> @endif

1 个答案:

答案 0 :(得分:0)

使用Auth::check() Details doc

@if(Auth::check() && (Auth::user()->id == $subjects->id)) // check your subjectsid ... may be you named it differently
<input style="text-align: center;border-radius:5px;"  type="submit"value="SUBMIT" class="btn btn-danger btn-sm">
@else<p>View Mode</p>
@endif