laravel - 来自公共类助手的 Laravel 更新表不起作用
问题描述
我想在我的公开课上更新我的表。但它抛出错误方法更新不存在。这是我的课
public static function Update($id, $city){
$hotel_name= hotel_info::all()->where('id', $id)->pluck('hotel_name');
$user_id = auth()->user()->id;
$plan_hotel_db = plan_hotel::where('travel_id', $user_id)->where('plan_city_id', $city)->get();
$plan_hotel_db->hotel_name = $hotel_name;
$plan_hotel_db->update();
return $plan_hotel_db;
}
解决方案
你应该得到你的第一个元素$plan_hotel_db
,因为它将返回一个数据数组。要解决此问题,请将您的代码更改为此。
public static function Update($id, $city){
$hotel_name= hotel_info::all()->where('id', $id)->pluck('hotel_name');
$user_id = auth()->user()->id;
$plan_hotel_db = plan_hotel::where('travel_id', $user_id)->where('plan_city_id', $city)->first();
$plan_hotel_db->hotel_name = $hotel_name;
$plan_hotel_db->update();
return $plan_hotel_db;
}
或者如果你想更新它的所有记录,那么你应该迭代$plan_hotel_db.
推荐阅读
- xamarin.forms - 将项目引用添加到 Xamarin Forms 应用程序
- python - 如何使用观察点 API 获取用户的位置
- java - 读取 Excel 标题和行值
- python-2.7 - 如何让一个函数检查多个事物
- python - 在 Python 环境中设置 NLTK 的问题
- php - Cloudflare 在 Digital Ocean 和 Wordpress 多站点前出现间歇性 521 错误
- node.js - Firebase 实时数据库多路径更新失败
- amazon-web-services - 尝试在 awsgosdk 的帮助下在 terratest 中调用 cloudwatch loggroupname 和 logstreamname
- python - 麻烦使用 tkinter,pandas 将列表复制到剪贴板
- json - 尝试在 SQL Server 2016 中查询 GeoJson 多面体的问题