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

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

如何在 Laravel 中顯示通知?

如何在 Laravel 中顯示通知?

PHP
楊__羊羊 2022-10-28 16:27:57
我有一個奇怪的問題。我有兩個通知類 InterviewRequestReceived.php 和 SendJobSeekerResume.php。我正在嘗試使用小鈴鐺圖標旁邊顯示通知總數count(),然后顯示與相應通知類相關的消息。消息很簡單,它們位于 /layouts/partials/notification 中。1. interview_request_received.blade.php<div>    <span class="font-weight-bold">You've been sent an Interview request!</span></div>2. send_job_seeker_resume.blade.php<div>    <span class="font-weight-bold">You've been sent a new Job Profile!</span></div>在我的管理文件中,我有 2 個角色,具體取決于用戶是作為求職者還是雇主登錄。admin.blade.php:兩個項目role_id === 1都在工作,我得到了計數和帶有消息的項目,但是role_id === 2我得到計數 0 的項目并且沒有帶有消息的項目,這很奇怪。當然,我正在查看和測試 2 個帳戶,其中我將 role_id 設置為 1 或將 role_id 設置為 2。這是我的通知表的屏幕截圖:當我使用 user_id 12(也將 role_id 設置為 2)登錄時,它應該顯示所有 notifiable_id 設置為 12 的通知。我死掉了我的兩個模型,看看是否有通知,像這樣的employeesProfile 和jobSeekerProfile 模型,我可以看到我的employeesProfile 模型中沒有通知,它只是一個空數組。下面是截圖。dd($employerProfile->notifications);
查看完整描述

1 回答

?
函數式編程

TA貢獻1807條經驗 獲得超9個贊

您收到來自錯誤模型的通知。


根據您的代碼和數據庫結構,假設登錄用戶 id 為 3,employer_profile_user_id則為 12


$user->unreadNotifications從notifications表 where notifiable_typeisApp\User和notifiable_idis中獲取記錄3;


$user->employerProfile->unreadNotifications從notifications表 where notifiable_typeisApp\EmployerProfile和notifiable_idis中獲取記錄12;


所以試試這個計數


@if(Auth::user()->role_id === 2)

      <!-- Counter - Alerts -->

      <span class="badge badge-danger badge-counter">{{ Auth::user()->employerProfile->unreadNotifications->where('type', 'App\Notifications\SendJobSeekerResume')->count() }}</span>

@endif

這是細節


@if(Auth::user()->role_id === 2)

       @foreach(Auth::user()->employerProfile->unreadNotifications as $notification)

       <a class="dropdown-item d-flex align-items-center" href="#">

            @include('layouts.partials.notification.'. Str::snake(class_basename($notification->type)))

                                    </a>

       @endforeach

@endif


查看完整回答
反對 回復 2022-10-28
  • 1 回答
  • 0 關注
  • 98 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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