php - 如何将数据和 url 从 ajax 传递到控制器?
问题描述
我有一个产品页面,我的画廊是产品的一个子类别。
Route::resource('products.galleries', 'GalleryController');
如何将两个 ID 传输到控制器?
product_id
gallery_id
阿贾克斯
@isset($gallery)
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content'),
},
type: 'POST',
url: '{{ route('products.galleries.destroy', [$product->id, $gajllery->id]) }}',
data : {
"_method" : "DELETE" ,
name
},
success: function (data) {
console.log(data);
},
error: function (e){
console.log(e);
},
});
@endisset
GalleryController.php
public function destroy(Product $product, Request $request)
{
$filename = $request->get('name');
dd($filename);
Gallery::where('image', $filename)->delete();
Storage::disk('public')->delete($filename);
}
它甚至没有向我们展示dd($filename);
。
注意:此代码完全没有错误。
解决方案
推荐阅读
- reactjs - 在 redux 状态更改后,React 导航不会更改导航屏幕
- java - 在 AWS 中标记 Step Function 任务
- python - 获取搜索页面结果,使用 jwt 身份验证登录(python)
- vue.js - 如何使用 Vuetify CSS 间距助手?
- drools - JBPM6 添加自定义节点
- regex - 如何创建过滤器来搜索具有特殊字符的单词,同时在没有特殊字符的输入中写入
- javascript - Splide Slider - 制作响应式滑块
- python - 如何将缩放时的matplotlib颜色条范围更改为缩放区域中数据的限制
- python - 用 Python 编写 Discord 机器人 - 为什么它无法设置嵌入图像?
- python - 在虚拟环境中安装 ipykernel 并运行 jupyter notebook - 不使用 conda