mistery23 / eloquent-flusher
此包已被弃用且不再维护。未建议替代包。
laravel 清空关系
v2.0.0
2019-12-18 13:59 UTC
Requires
- php: ^7.2
- illuminate/database: ~5.8.0|^6.0
README
延迟推送实体
安装
composer require mistery23/eloquent-flusher
使用
use Mistery23\Flusher;
class Role extends Model
{
use Flusher;
....
/**
* For BelongsToMany.
* Detach permission from a role.
*
* @param string $permissionId
*/
public function detachPermission($permissionId): void
{
$this->detachItem('permissions', $permissionId);
}
.....
/**
* For HasMany.
* Detach role translations from a role.
*
* @param string $locale
*
* @return void
*/
public function detachTranslation(string $locale): void
{
$translation = $this->translations->where('locale', $locale)->first();
$this->detachItem('translations', $translation);
}
}
并在仓库中刷新
/**
* Update role
*
* @param Role $role
*
* @return void
*
* @throws \RuntimeException
*/
public function update(Role $role): void
{
if (false === $role->flush()) {
throw new \RuntimeException('Update error.');
}
}
许可
此包为免费软件,根据MIT许可协议分发。祝您使用愉快!