【发布时间】:2018-07-10 22:39:50
【问题描述】:
我需要在保存贷款时更新模型关系中图书的status字段,但它不起作用。
我的代码
class Lending extends Model
{
/**
* @var string The database table used by the model.
*/
public $table = 'ribsousa_library_lendings';
/*
* Relations
*/
public $belongsToMany = [
'books' => [
'Ribsousa\Library\Models\Book',
'table' => 'ribsousa_library_lendings_books',
'order' => 'title desc'
]
];
public function afterSave()
{
$this->book->status = 1;
$this->book->save();
}
}
错误:
`"Indirect modification of overloaded property Ribsousa\Library\Models\Lending::$book has no effect" on line 95 of C:\wamp64\www\iepm.dev\plugins\ribsousa\library\models\Lending.php`
【问题讨论】:
-
试试
formAfterSaveoctobercms.com/docs/api#formaftersave -
更新了我的答案,请检查一次。
标签: model relation octobercms