亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

如何修改 Eloquent 關系并將其傳遞給 Blade

如何修改 Eloquent 關系并將其傳遞給 Blade

PHP
蠱毒傳說 2021-10-22 15:03:41
我需要修改 Eloquent 關系(它可以改變值,或洗牌,或刪除某些項目)在控制器中,您可以這樣做:$question = Question::first();//$question has a relationship with Answer, therefore I have $question->answers.$question->answers = $this->modifyAnswers($question->answers);dd($question->answers) //Worked! Displaying modified Answersreturn view('someView', compact($question));//In the blade file, it's receiving original $question->answers解決方法是添加具有不同名稱的新屬性。$question->modifiedAnswers = $this->modifyAnswers($question->answers);//And blade can access $question->modifiedAnswers但是有什么方法可以讓我在不添加其他屬性的情況下修改值?
查看完整描述

1 回答

?
HUH函數

TA貢獻1836條經驗 獲得超4個贊

你可以,用這個方法 setRelation($name, $value)


$question = Question::first();


$question->setRelation('answers', $this->modifyAnswers($answers));


dd($question->relationLoaded('answers'));

更多信息在這里文檔


查看完整回答
反對 回復 2021-10-22
  • 1 回答
  • 0 關注
  • 152 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號