Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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
Laravel 我们是否可以通过route()方法在锚定标记中从blade传递PUT、PATCH和DELETE请求?_Laravel_Http_Httpverbs_Laravel 6.2 - Fatal编程技术网

Laravel 我们是否可以通过route()方法在锚定标记中从blade传递PUT、PATCH和DELETE请求?

Laravel 我们是否可以通过route()方法在锚定标记中从blade传递PUT、PATCH和DELETE请求?,laravel,http,httpverbs,laravel-6.2,Laravel,Http,Httpverbs,Laravel 6.2,重新表述问题:我知道它是如何通过表单提交和ajax请求工作的,我一直在寻找是否有任何方法可以发送“数据”,只需调用URL(如下所述)进行放置,补丁和删除和csrf令牌将从内核>中间件获取,而不是通过表单提交 我一直在尝试使用此方法destroy()DELETE方法从刀片文件中运行,如下所示 我们可以重写这个方法吗 if (! function_exists('route')) { /** * Generate the URL to a named route. *

重新表述问题:我知道它是如何通过表单提交和ajax请求工作的,我一直在寻找是否有任何方法可以发送“数据”,只需调用URL(如下所述)进行放置,补丁和删除csrf令牌将从内核>中间件获取,而不是通过表单提交

我一直在尝试使用此方法
destroy()
DELETE方法从刀片文件中运行,如下所示

我们可以重写这个方法吗

if (! function_exists('route')) {
    /**
     * Generate the URL to a named route.
     *
     * @param  array|string  $name
     * @param  mixed  $parameters
     * @param  bool  $absolute
     * @return string
     */
    function route($name, $parameters = [], $absolute = true)
    {
        return app('url')->route($name, $parameters, $absolute);
    }
}
这就是我给route打电话的方式

Route::resource('employees','EmployeeController');
我可以这样做来实现我想要的

Route::get('employees/{employees}','EmployeeController@destroy')->name('employees.destroy');
Route::resource('employees','EmployeeController')->except([
    'destroy'
]);

可能是您的解决方案:

<form action="{{ route('employees.destroy', ['id' => $key->id]) }}" method="post">
    <input class="btn btn-default" type="submit" value="Delete" />
    @method('delete')
    @csrf
</form>

@方法('delete')
@csrf

您到底想做什么?Delete方法必须始终需要像表单提交一样通过。不能直接从锚点传递删除管线。这是需要完成的,因为每条路线都需要通过
csrf()
,而锚定标签中无法给出。请参考下面的答案。不,我的意思是像传递csrf令牌一样,方法名像“DELETE”一样,在默认的laravel route()methodok@Vipertecpro的参数中。但通常,这是下面提到的最被接受的方法。