【问题标题】:can I use my controller in laravel 8 to delet row that checked in view?我可以在 laravel 8 中使用我的控制器来删除检入视图的行吗?
【发布时间】:2021-09-03 18:52:27
【问题描述】:
@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

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

【问题讨论】:

  • 表单元素进入inside &lt;form&gt;...&lt;/form&gt;(除非有form 属性)。 &lt;a href&lt;button&gt; 中没有多大意义

标签: php html controller laravel-blade laravel-8


【解决方案1】:

我认为 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

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

【讨论】:

    猜你喜欢
    • 2019-09-06
    • 2021-06-12
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多