访问附加属性时尝试获取非对象错误的属性

时间:2018-09-08 17:49:44

标签: php laravel laravel-5.4

假设有一个function findAndConvertDates<T extends { [key: string]: any }>(objectWithStringDates: T): T {模型,我想添加一个名为Website的访问器,如下所示:

min_withdraw

该访问器使用class Website extends Authenticatable { protected $primaryKey = 'website_id'; protected $appends = ['min_withdraw']; protected $hidden = [ 'password', 'remember_token', 'min_withdraw' ]; function getMinWithdrawAttribute () { if (!empty($this->settingOf('website','min_withdraw_user'))) { return $this->settingOf('website','min_withdraw_user'); } return 100; } } 方法来获取名为settingOf()的设置。 min_withdraw_user的正文类似于:

settingOf()

public function settingOf ($type, string $key, string $nestedKey = null) { $type = is_null($type) ? 'website' : $type; $setting = Setting::of($type, $key, $nestedKey, $this); return !empty($setting) ? $setting : Setting::of($type, $key, $nestedKey); } 还使用settingOf模型,其中包含项目中定义的不同模型的一些设置。

Setting方法的输出之类的所有东西都符合我的预期。

但是当我想访问该访问器settingOf时,总是出现此错误:

min_withdraw

即使我在刀片模板中使用Trying to get property of non-object (View: D:\wamp\www\loverspay\resources\views\main\pages\index.blade.php) 时,它也返回正确的值,但是当我想像{{dd($website->min_withdraw)}}那样以正常方式回显时,我得到了该错误。

什么是问题?

更新:

此外,我使用波纹管代码获得了一些网站,然后将它们发送到Controller中所需的刀片服务器模板:

{{$website->min_withdraw}}

0 个答案:

没有答案