我在下面有更新功能,但它返回此错误:Illuminate\Database\QueryException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name1' in 'where clause' (SQL: select count(*) as aggregate from `groups` where `name1` = postman group)问题: ID added to column name: Unknown column 'name1',我看不到发生这种情况的地方。代码public function update(Request $request, $id){ $user = $request->user(); $group = Group::findOrFail($id); $isAdmin = $user->groupsAdmin()->whereName($group->name)->exists(); if($isAdmin) { $rules = [ 'name' => 'required|string|max:255|unique:groups,name' . $id, 'description' => 'nullable|string|max:255', ]; if ($request->hasFile('photo')) { $rules['photo'] = 'mimetypes:image/jpeg,image/png|max:2048'; } $this->validate($request, $rules); $group->name = $request->input('name'); $group->description = $request->input('description'); if ($request->hasFile('photo')) { $photo = $request->file('photo'); $filename = 'Group' . '-' . time() . '.' . $photo->getClientOriginalExtension(); $location = public_path('images'); $request->file('photo')->move($location, $filename); $oldFilename = $group->photo; $group->photo = $filename; if(!empty($group->photo)){ Storage::delete($oldFilename); } } $group->save(); return response()->json([ 'data' => new GroupResource($group), 'message' => 'Your group updated successfully.' ]); } else { return response()->json([ 'data' => null, 'message' => 'Only admins can edit group details.' ]); }}任何想法?
1 回答
守着星空守着你
TA贡献1799条经验 获得超8个赞
你需要在 the 后面加一个逗号,groups,name
因为 unique 规则是这样写的unique:table,column,except,idColumn
- 1 回答
- 0 关注
- 98 浏览
添加回答
举报
0/150
提交
取消