1 回答

TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊
您可以創(chuàng)建一個(gè)觀察者來(lái)自動(dòng)更新該字段。
NotificationObserver.php
namespace App\Observers;
class NotificationObserver
{
public function creating($notification)
{
$notification->project_id = $notification->data['project_id'] ?? 0;
}
}
事件服務(wù)提供者.php
use App\Observers\NotificationObserver;
use Illuminate\Notifications\DatabaseNotification;
class EventServiceProvider extends ServiceProvider
{
public function boot()
{
parent::boot();
DatabaseNotification::observe(NotificationObserver::class);
}
}
您應(yīng)該能夠使用默認(rèn)模型訪問(wèn)表以執(zhí)行操作。
DatabaseNotification::where('project_id', 11)->delete();
- 1 回答
- 0 關(guān)注
- 188 瀏覽
添加回答
舉報(bào)