laravel 资源控制器 依赖注入的模型 更新操作前的模型 与 更新后的模型 不一致


public
function update(Request $request, FangInfo $fangInfo) { dump($fangInfo); //表单数据 $postData = $request->except(['_token', 'file']); //没入库之前,$fangInfo 是修改前的数据,即是原始数据 //入库之后,$fangInfo 是更新之后的数据 dump($fangInfo); //打印出来数据不一样,可根据需求对更新后的数据进行操作,$fangInfo->update($postData)返回的是true, //和FangInfo::updated()不一样,FangInfo::updated()会返回更新成功后的模型 //入库 if ($fangInfo->update($postData)) { //入库成功后 //发起Http请求 $client = new Client(['timeout' => 5]); //得到URL地址 $url = config(''); $city = City::findOrFail($fangInfo->fang_city); $url = sprintf($url, $fangInfo->fang_addr, $city->name); //发起请求 $response = $client->get($url); //可尝试 打印$response看看 $body = (string)$response->getBody(); $arr = json_decode($body, true); //如果 } return redirect(route('')); }

$fangInfo->update($postData)  和    FangInfo::updated() 的区别;

原文地址:https://www.cnblogs.com/zqblog1314/p/12783062.html