如果用户已通过身份验证且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
答案 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