首页 > 解决方案 > Laravel 通知(数据库通知)图标不会改变

问题描述

大家好,如果有来自 github 的推送事件,我尝试为管理员用户发送实时通知以获取通知。

我已经制作了一个通知表并收到通知,问题是通知图标没有改变,并在有新通知时放置 1++,我需要先刷新页面才能更改图标。

这是我的控制器。

public function index(Request $request){
        view()->share('page_sub', 'Webhhook');

        $data = Cache::store('file')->get('repo');

        // dd($data);

        return view('pages.admin.system.webhook.index')->with('data',$data);
    }

    public function handle(Request $request){

        // $data = $request;

        $admins = User::whereHas('roles', function($q){$q->whereIn('roles.name', ['superadmin']);})->get();

        $data = [
            'id' => $request['repository']['id'],
            'name' => $request['repository']['name'],
            'tags_url' => $request['repository']['tags_url'],
            'archive_url' => $request['repository']['archive_url'],
            'updated_at' => $request['repository']['updated_at'],
        ];

        $now = \Carbon\Carbon::now();

        $repo_data = cache('repo');

        \Log::info($data);

        if ($data['updated_at'] != $repo_data['updated_at']) {
            Cache::store('file')->put('repo', $data, $now->addMonth());
        }

        foreach($admins as $user){
            $user->notify(new  WebhookNotification($repo_data));
        }
    }

这是图标所在的我的标题。

       <div class="an-notifications" id="notify">
            <div class="btn-group an-notifications-dropown notifications" >

                @if (count(auth()->user()->unreadNotifications) > 0 ) 

                    <button type="button"  class="an-btn an-btn-icon dropdown-toggle js-has-new-notification" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="notif">
                        <i class="ion-ios-bell-outline"></i>
                    </button>

                @elseif (count(auth()->user()->unreadNotifications) === 0 ) 

                    <button type="button"  class="an-btn an-btn-icon dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="notif">
                        <i class="ion-ios-bell-outline"></i>
                    </button>

                @endif

                <div class="dropdown-menu">
                    <p class="an-info-count">Notifications <span>{{count(auth()->user()->unreadNotifications)}}</span></p>
                    <div class="an-info-content notifications-info notifications-content">


                        <ul class="nav">
                            <li>
                                @forelse(auth()->user()->unreadNotifications as $notification)

                                    <div class="an-info-single unread" id="notif">
                                        <a href="{{url('iaccs-hook-list')}}">
                                            <span class="icon-container important">
                                                <i class="icon-setting"></i>
                                            </span>
                                            <div class="info-content">
                                                <h5 class="user-name">Update Client</h5>
                                                <p class="content"><i class="icon-clock"></i> {{$notification->created_at}}</p>
                                            </div>
                                        </a>
                                    </div>
                                    @empty
                                    <a href="">No Unread Notification</a>

                                @endforelse
                            </li>
                        </ul>

                    </div> <!-- end .AN-INFO-CONTENT -->
                    <div class="an-info-show-all-btn">
                        <a class="an-btn an-btn-transparent fluid rounded uppercase small-font" href="#">Show all</a>
                    </div>
                </div>
            </div>
        </div> <!-- end .AN-NOTIFICATION -->

我需要安装 Laravel echo 吗?还是我错过了一些代码?

谢谢你。

标签: laravel-5.6

解决方案


推荐阅读