我想在 laravel 的表单模式下向我的删除按钮添加一个构象按钮



在Laravel中,我希望我的删除按钮为其添加确认选项:

{!!Form::open(['action'=>['PostsController@destroy', $posts->id], 'method'=> 'POST', 'class' => 'float-right'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class'=>'btn btn-danger'])}}
{!!Form::close()!!} 

这是我想在其中添加一个确认弹出窗口的代码,该弹出窗口将要求您确认是否要删除。

您可以将其替换为按钮。

{!!Form::open(['action'=>['PostsController@destroy', $posts->id], 'method'=> 'DELETE', 'class' => 'float-right'])!!}
{!! Form::button('Delete', ['type'=>'submit','value'=>'delete','class'=>'btn btn-danger','onclick'=>"return confirm('Are you sure?')"]) !!}
{!!Form::close()!!} 

这是我在项目中经常使用的一个片段。这是一个默认的 Web 浏览器警报弹出窗口。它会创建一个隐藏窗体,并将要删除的属性的 ID 附加到其中。

<div class="pl-1">
<button type="button" name="button"
onclick="if(confirm('Are you sure you want to delete this?')){ $('form#delete-{{$obj->id}}').submit(); }"
class="btn btn-danger btn-sm">Delete
</button>
{!! Form::open(['method' => 'DELETE', 'route' => ['your_route.destroy',$obj->id], 'class' => 'hidden', 'id'=>"delete-".$obj->id]) !!}
{!! Form::close() !!}
</div>

相关内容

最新更新