第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ErrorException: 對重載屬性 App\Answer::$attribute

ErrorException: 對重載屬性 App\Answer::$attribute

PHP
阿晨1998 2021-10-15 17:31:58
當(dāng)我嘗試從我的答案表數(shù)據(jù)庫中更改“ans”屬性的值時,出現(xiàn)此異常。public function setAnsAttribute($ans){}ErrorException: 對重載屬性App\Answer::$attribute 的間接修改無效
查看完整描述

2 回答

?
梵蒂岡之花

TA貢獻(xiàn)1900條經(jīng)驗(yàn) 獲得超5個贊

setAnsAtribute 方法沒有代碼?如果您有代碼,請?zhí)砑痈啻a以查看發(fā)生了什么。謝謝你。


如果您沒有代碼,我會在下面指出。


我將您推薦給 Laravel Mutators頁面,以便您可以查看示例并附上示例代碼以及您正在嘗試執(zhí)行的操作。


función pública setAnsAttribute ($value) {

    /**

     *  You can transform the value or modify other values in the table here, 

     *  according to your needs.

     */

    $this->attributes['ans'] = $value;

}


查看完整回答
反對 回復(fù) 2021-10-15
?
森欄

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個贊

我從來沒有遇到過這個錯誤,所以我做了一些研究并創(chuàng)建了以下內(nèi)容來說明這個問題:


班上:


class SomeMagicMethodImplementer

{

    private $properties = [];


    public function __get($k)

    {

        return $this->properties[$k] ?? null;

    }


    public function __set($k, $v)

    {

        $this->properties[$k] = $v;

    }

}  

用法:


$impl = new SomeMagicMethodImplementer();

$impl->bar = 'bar';

print_r($impl->bar); // prints bar

$impl->foo[] = 'foo';

錯誤原因:


$impl->foo[] = 'foo' // Will throw error: Indirect modification of overloaded property

間接修改重載屬性


使用上面的示例代碼,該錯誤基本上指出經(jīng)由魔設(shè)定器創(chuàng)建的任何屬性可以僅通過專用實(shí)例變量進(jìn)行修改$properties。


在 Laravel 和模型的上下文中,屬性只能通過 protected 實(shí)例變量進(jìn)行修改$attributes。


Laravel 示例:


public function setAnsAttribute($value)

{

    // output will be an array

    $this->attributes['ans'][] = $value;

}


查看完整回答
反對 回復(fù) 2021-10-15
  • 2 回答
  • 0 關(guān)注
  • 180 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號