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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Laravel 通知存儲(chǔ)附加 ID 字段

Laravel 通知存儲(chǔ)附加 ID 字段

PHP
桃花長(zhǎng)相依 2022-01-14 15:06:00
所以我設(shè)置了 Laravel 通知,它工作得很好。但是,我已經(jīng)擴(kuò)展了遷移以包含一個(gè)額外的 id 字段:$table->integer('project_id')->unsigned()->nullable()->index();問(wèn)題是,我不知道如何實(shí)際設(shè)置該project_id字段。我的通知如下所示:<?phpnamespace App\Notifications\Project;use App\Models\Project;use App\Notifications\Notification;class ReadyNotification extends Notification{    protected $project;    public function __construct(Project $project)    {        $this->project = $project;    }    public function toArray($notifiable)    {        return [            'project_id' => $this->project->id,            'name' => $this->project->full_name,            'updated_at' => $this->project->updated_at,            'action' => 'project-ready'        ];    }}所以是的,我可以將它存儲(chǔ)在數(shù)據(jù)中,但是如果我想通過(guò)“項(xiàng)目”而不是“用戶”或“通知”專門清除通知怎么辦。data例如,如果他們刪除項(xiàng)目,我希望清除它的通知,但除非我在列上進(jìn)行一些通配符搜索,否則無(wú)法訪問(wèn)它。那么無(wú)論如何要project_id在通知中插入它嗎?
查看完整描述

1 回答

?
慕容3067478

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();


查看完整回答
反對(duì) 回復(fù) 2022-01-14
  • 1 回答
  • 0 關(guān)注
  • 188 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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