gpt4 book ai didi

javascript - 仅向 Laravel 中的登录用户显示按钮

转载 作者:可可西里 更新时间:2023-11-01 00:39:49 25 4
gpt4 key购买 nike

如果我以 John 身份登录,我如何才能只显示 John 的红色按钮而不显示 Susan 的红色按钮?

测试系统环境:Win10、Laravel5.4、Mysql5.7.19。

enter image description here

<table class="table table-responsive" id="jobs-table">
...
@foreach($jobs as $job)
<tr>
<td>{!! $job->user_name !!}</td>
...
<td>{!! $job->created_at !!}</td>
<td>
{!! Form::open(['route' => ['jobs.destroy', $job->id], 'method' => 'delete']) !!}
<div class='btn-group'>
<a href="{!! route('jobs.show', [$job->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-eye-open"></i></a>
<a href="{!! route('jobs.edit', [$job->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-edit"></i></a>
{!! Form::button('<i class="glyphicon glyphicon-stop"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure to Stop?')"]) !!}
</div>
{!! Form::close() !!}
</td>
</tr>
@endforeach

最佳答案

使用 Laravel policies特点:

@can('delete', $job)
{!! Form::button('<i class="glyphicon glyphicon-stop"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure to Stop?')"]) !!}
@endcan

或:

@if (auth()->user()->can('delete', $job))
{!! Form::button('<i class="glyphicon glyphicon-stop"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure to Stop?')"]) !!}
@endif

关于javascript - 仅向 Laravel 中的登录用户显示按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46703535/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com