我试图通过API存储前端的历史数据(颤振)。下面是拉拉控制器。然而,当我在postman上运行它时,出现了一个错误,列中找不到:‘字段列表’中的1054个未知列“图像”。我认为它正在检索整个用户列。从专栏中,我只看到了staff_id、date_checkIn、time_checkIn和location_checkIn。我该怎么解决这个问题?
我试过User::where('staff_id', 'date_checkIn', 'time_checkIn', 'location_checkIn')->first()->toArray();。但上面写着
语法错误或访问冲突: 1064您的SQL语法出现了错误;请检查与MariaDB服务器版本对应的手册,以获得在第1行( location_checkIn staff_id = date_checkIn限制1)附近使用“staff_id=?限制1”的正确语法……
public function userClockIn(Request $r) {
$result = [];
$result['status'] = false;
$result['message'] = "something error";
$users = User::where('staff_id', $r->staff_id)->first();
// retrieve current data
$currentData = $users->toArray();
// store current data in historical data table
$historicalData = new HistoricalData();
$historicalData->fill($currentData);
$historicalData->save();
$mytime = Carbon::now();
$time = $mytime->format('H:i:s');
$date = $mytime->format('Y-m-d');
$users->date_checkIn = $date;
$users->time_checkIn = $time;
$users->location_checkIn = $r->location_checkIn;
$users->save();
$result['data'] = $users;
$result['status'] = true;
$result['message'] = "suksess add data";
return response()->json($result);
}发布于 2022-12-03 13:52:51
要修复此错误,需要指定要从where子句的users表中检索的列。可以通过使用select方法并传入要选择的列的数组来实现这一点。
下面是一个如何更新代码以修复错误的示例:
$users = User::where('staff_id', $r->staff_id)->select(['staff_id', 'date_checkIn', 'time_checkIn', 'location_checkIn'])->first();这只会从users表中检索指定的列,而不会导致错误。
https://stackoverflow.com/questions/74667272
复制相似问题