微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我可以在laravel 8 中使用我的控制器来删除在视图中签入的行吗?

如何解决我可以在laravel 8 中使用我的控制器来删除在视图中签入的行吗?

@extends('layouts.app')
@section('content')

    <body>
        <button class="btn" onclick="deleteSelected()">delete</button>
        <table class="table">
            <thead>
                <tr>
                    <th scope="col">
                        <input type="checkBox" id="all" onclick="chkd()">
                    </th>
                    <th scope="col">id</th>
                    <th scope="col">title</th>
                    <th scope="col">Paragraph</th>
                </tr>
            </thead>
            @foreach ($categories as $categorie)
                <tbody>
                    <tr>
                        <td>
                            <input type="checkBox" class="ss" value="{{ $categorie->id }}" onclick="deleteSelected()">
                        </td>
                        <th scope="row">{{ $categorie->id }}</th>
                        <td>{{ $categorie->Title }}</td>
                        <td>{{ $categorie->Paragraph }}</td>
                        <form action={{ route('categorie.destroy',$categorie->id) }} method="POST">
                            @csrf
                            @method('DELETE')
                            <td>
                                <button id="deleteRow" class="btn btn-danger" type="submit" style="display: none">
                                    delete
                                </button>
                        </form>
                        <button class="btn btn-warning"> <a href={{ route('edit',$categorie->id) }}>edit</a> </button>
                        </td>
                    </tr>
                </tbody>
            @endforeach
        </table>
 </body>
@endsection

这就是我的观点,当我选中一个复选框并按下按钮删除时,我希望删除该行,或者当我选中所有我想删除所有行时

解决方法

我认为 html input 必须在 form 内。像这样移动代码怎么样:

    @foreach ($categories as $categorie)
        <tbody>
            <tr>
                <td>
                    <form action={{ route('categorie.destroy',$categorie->id) }} method="POST">
                    @csrf
                    @method('DELETE')
                        <input type="checkbox" class="ss" value="{{ $categorie->id }}" onclick="deleteSelected()">
                        <button id="deleteRow" class="btn btn-danger" type="submit" style="display: none">
                            delete
                        </button>
                    </form>
                </td>
                <th scope="row">{{ $categorie->id }}</th>
                <td>{{ $categorie->Title }}</td>
                <td>{{ $categorie->Paragraph }}</td>
                <td><button class="btn btn-warning"> <a href={{ route('edit',$categorie->id) }}>edit</a> </button></td>
            </tr>
        </tbody>
    @endforeach

但是,我不知道这是否可以解决您的问题。我看不到整个代码

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。