Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未定义路线_Php_Laravel - Fatal编程技术网

Php 未定义路线

Php 未定义路线,php,laravel,Php,Laravel,我对拉雷维尔很陌生,我对路线非常糟糕。我想删除特定数据,但它说路由未定义 CandidateController.php 这是我删除的方法 路线 Route::resource('candidates', CandidateController::class); @foreach ($candidates as $candidate) <div class="modal__content">

我对拉雷维尔很陌生,我对路线非常糟糕。我想删除特定数据,但它说路由未定义

CandidateController.php 这是我删除的方法

路线

Route::resource('candidates', CandidateController::class);
 @foreach ($candidates as $candidate)
                            <div class="modal__content">
                                <div class="p-5 text-center"> <i data-feather="x-circle" class="w-16 h-16 text-theme-6 mx-auto mt-3"></i>
                                    <form action="{{ route('candidates.destroy', $candidate->id) }}" method="POST">
                                        @csrf
                                        @method('DELETE')
                                        <div class="text-3xl mt-5">Are you sure?</div>
                                        <div class="text-gray-600 mt-2">Do you really want to delete these records? This process cannot be undone.</div>

                                        <button type="button" data-dismiss="modal" class="button w-24 border text-gray-700 dark:border-dark-5 dark:text-gray-300 mr-1">Cancel</button> 
                                        <button type="submit" title="delete" class="button w-24 bg-theme-6 text-white" >Delete</button> 
                                </div>
                                <div class="px-5 pb-8 text-center"> 
                            </div>
                        </div>
                    </form>
                        </div>
                        @endforeach
我正在使用一个资源库,当我阅读教程时,它将我的代码缩短为上面的代码。当我点击删除按钮时,它显示未定义的路线[candidate.approve]。有人能帮我找出哪里出了问题吗

刀片

Route::resource('candidates', CandidateController::class);
 @foreach ($candidates as $candidate)
                            <div class="modal__content">
                                <div class="p-5 text-center"> <i data-feather="x-circle" class="w-16 h-16 text-theme-6 mx-auto mt-3"></i>
                                    <form action="{{ route('candidates.destroy', $candidate->id) }}" method="POST">
                                        @csrf
                                        @method('DELETE')
                                        <div class="text-3xl mt-5">Are you sure?</div>
                                        <div class="text-gray-600 mt-2">Do you really want to delete these records? This process cannot be undone.</div>

                                        <button type="button" data-dismiss="modal" class="button w-24 border text-gray-700 dark:border-dark-5 dark:text-gray-300 mr-1">Cancel</button> 
                                        <button type="submit" title="delete" class="button w-24 bg-theme-6 text-white" >Delete</button> 
                                </div>
                                <div class="px-5 pb-8 text-center"> 
                            </div>
                        </div>
                    </form>
                        </div>
                        @endforeach

只需添加带有候选的新路线。在路线::资源之前批准名称

您的web.php文件如下所示

Route::get('your-url', [CandidateController::class, 'approve')->name('candidate.approve');
Route::resource('candidates', CandidateController::class);
但最好对命名路由使用prural,如资源控制器:

  • 候选人。创建
  • 小店
  • 更新

    因为我知道应用程序的流程,所以您应该在控制器上使用:

    return back();
    

    为什么??因为当管理员在modal上单击Delete时,它将转到另一个URL以从DB中删除数据。删除后,return back()会将管理员重定向到上一个URL

    这很可能是因为在web.php文件中没有定义实际的路由
    候选。请批准。指定管线名称时。使用
    php artisan route:list检查您的路由,您将获得所有路由您的销毁路由将是
    候选路由。销毁
    @Tithira我遵循文档,但它说缺少[route:candidates.destroy][URI:candidates/{candidate}]的必需参数是的,您需要传递路由的参数,哪个是
    主键
    或您的型号。默认情况下,
    id
    是主键。Destroy方法接受控制器函数中的主键并返回一个实例,因此在动作触发器中传递路由参数
    {route('candidates.Destroy',['candidate'=>$candidate->id])}
    实际上我已经将id放入动作触发器中,但仍然不起作用我尝试了,但路由仍然未定义:((向我们展示您的web.php内容。同时检查您的刀片服务器(idk或带有href=route('candidate.approve')的标签)我更新了我的问题,其中包括blade和web。PHP用户删除候选人后的流程是什么?也许这有助于我改进我的回答。它将返回到同一个blade。假设我的blade显示候选人列表,然后管理员单击候选人a“删除”按钮,它将出现一个弹出确认,然后管理员单击删除后,它将重定向到同一刀片,但候选人a不再存在