问题:
我正在使用laravel表单向数据库发出DELETE
请求,现在我有一个submit
字段,Laravel包含了该字段,但我想显示一个图标。
代码:
{!! Form::open(['action' => ['TasksController@destroy', $task->id],'method' => 'POST', 'class'=> 'float-right']) !!}
{{Form::hidden('_method','DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-outline-danger'])}}
{!! Form::close() !!}
我想要的:
{{Form::submit('Delete', ['class' => 'btn btn-outline-danger'])}}
// want to replace submit field with icon
<i class="far fa-trash-alt icon-size"></i>
答案 0 :(得分:2)
您可以使用此:
{{Form::button('<i class="far fa-trash-alt icon-size"></i>', ['type' =>'submit', 'class' => 'submit-btn'])}}
具有隐藏按钮的样式:
.submit-btn {
padding:0;
background: none;
border:none;
}
代替:
{{Form::submit('Delete', ['class' => 'btn btn-outline-danger'])}}
答案 1 :(得分:1)
您可以将表单包裹一些东西,隐藏起来,然后通过js提交。像这样:
<style>.form-wrapper>form{/*hide the form, change cursor to pointer, etc*/}</style>
<div class="form-wrapper" onclick="$(this).getElementsByTagName('form')[0].submit()">
<i class="far fa-trash-alt icon-size"></i>
{!! Form::open(['action' => ['TasksController@destroy', $task->id],'method' => 'POST', 'class'=> 'float-right']) !!}
{{Form::hidden('_method','DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-outline-danger'])}}
{!! Form::close() !!}
</div>