![](/img/trans.png)
[英]Guzzle http and Laravel Http post method replace with get method. 405 Method Not Allowed
[英]method not allowed using guzzle
我想通過對HTTP請求使用guzzle通過id刪除數據,但不允許使用方法
查看文件
<div class="panel-heading clickable">
<h3 class="panel-title">
<a href="/delete/{{$value['id']}}" style="float: right;" data-method="delete">Delete</a>
{{ $value['nama'] }}
</h3>
</div>
路線文件
Route::post('/delete/{id}', 'adminController@deleteBidang');
控制器文件
public function deleteBidang(Request $request){
$client = new Client([
'base_uri' => 'http://localhost:8000/api',
'http_errors' => false,
'debug' => true
]);
$result = $client->delete('http://localhost:8000/api/admin/kategori/bidang/{id}');
return redirect('admin/cattegory');
}
有什么解決辦法?
您錯誤地使用了刪除ID,請像這樣使用。
$result = $client->delete("http://localhost:8000/api/admin/kategori/bidang/{$request->id}");
首先,您應該在刀片服務器模板中使用laravel url路由
<a href="{{ url('/delete/'.$value['id']) }}" style="float: right;" data-method="delete">Delete</a>
並且您的控制器應如下所示。 您沒有在函數中獲取$ id。 網址也不正確。 據我所知這應該工作
public function deleteBidang(Request $request, $id){
$client = new Client([
'base_uri' => 'http://localhost:8000/api',
'http_errors' => false,
'debug' => true
]);
$result = $client->delete('http://localhost:8000/api/admin/kategori/bidang/'.$id);
return redirect('admin/cattegory');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.