脚本宝典收集整理的这篇文章主要介绍了php – 在非对象上调用成员函数fill(),脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$user = User::whereUsername($username)->FirstOrFail(); // Selects correct user $input = Input::all(); // a dd($input) at this point confirms input PResent $this->profileForm->validate($input); // Passes $user->profile->fill($input)->save(); return redirect::route('profile.edIT',$user->username);
如果$user-> profile为null,则会出现错误:调用非对象上的成员函数fill().我尝试用以下方法解决这个问题:
$user = User::whereUsername($username)->firstOrFail(); // Selects correct user $input = Input::all(); // a dd($input) at this point confirms input present $this->profileForm->validate($input); // Passes if ($user->profile == null) { $user->profile = new Profile; } $user->profile->fill($input)->save(); return Redirect::route('profile.edit',$user->username);
if (count($user->profile)) { $user->profile->fill($input)->save(); } else { $profile = Profile::create($input); $user->profile()->save($profile); }
以上是脚本宝典为你收集整理的php – 在非对象上调用成员函数fill()全部内容,希望文章能够帮你解决php – 在非对象上调用成员函数fill()所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。