簡體   English   中英

Laravel 5在銷毀路線上缺少必需的參數

[英]Laravel 5 missing required parameters on destroy route

我最近從laravel 5.1升級到5.2,現在遇到Missing required parameters for [Route: example.destroy] [URI: example/{args}]的錯誤。

錯誤發生在這里: <form class="form-horizontal" action="<?php echo route('example.destroy'); ?>" method="post">表單的action屬性。

這是在route.php注冊路線的route.php

Route::resource('example', 'ExampleController');

當我使用5.1時,此行沒有錯誤。 我剛升級到5.2,現在發生了。

其功能是允許用戶通過選中希望刪除的復選框來刪除多個條目。 然后在提交后,它將重定向到控制器上的destroy方法。

您可以嘗試以下

<form class="form-horizontal" action="<?php echo       
url('example'); ?>" method="post">

Route::post('example', 'ExampleController@destroy');

將我的應用程序更新為Laravel 5.2時,我遇到了同樣的問題。

顯然,Laravel 5.2需要一個有效的路由來“銷毀資源”,例如:

/my-route/item-to-destroy/{id}

在這里,在我們的應用程序中,我將在每個路徑的末尾放置“ {id} = 0”或“ {id} = null”(當調用尚未准備好的“路徑破壞”時)。

在您的情況下,它類似於:

<form action="<?php echo route('example_route.destroy', ['id'=>0]); ?>" method="post">

或者,聲明有效的資源ID:

<form action="<?php echo route('example_route.destroy', ['id'=>$object->id]); ?>" method="post">

試試這個:

<form class="form-horizontal" action="<?php echo route('example.destroy', $record->id); ?>" method="post">

或Laravel方式:

{!! Form::open(['route' => ['example.destroy', $record->id],
                                                'method' => 'delete']) !!}

{!! Form::close() !!}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM