如何插入@if语句仅显示" 红色删除操作按钮"以下代码中的用户?
{!! 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() !!}
谢谢你的到来。
答案 0 :(得分:1)
您可以像这样使用Auth::check()
:
{!! 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>
@if (Auth::check())
{!! 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
</div>
{!! Form::close() !!}
答案 1 :(得分:1)
我认为你正在寻找类似的东西:
<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>
@if(Auth::check())
{!! Form::open(['route' => ['jobs.destroy', $job->id], 'method' => 'delete']) !!}
{!! Form::button('<i class="glyphicon glyphicon-stop"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure to Stop?')"]) !!}
{!! Form::close() !!}
@endif
</div>
请注意,我已将您的表单移到if语句中,如果您仍然希望将其他按钮包含在表单中,请使用以下代码
{!! 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>
@if(Auth::check())
{!! 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
</div>
{!! Form::close() !!}