@D9705996 - It sad to say that it's only support in Laravel 5.7.... By the way sir this is my case...
Case: If there's a push in a github repo it will notify the user (admin)..
I implemented like this.
-
I set my api route in github webhook payload URL
-
This was the link that I set in github payload URL.
Route::post('iaccs-hook', 'WebhookController@handle');
In my controller:
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));
}
}
It will notify the user but the problem is you need to refresh the page first for the notif icon will popup...
This was my header view...
<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 -->
What do I missed? or how should I implemented sir that if there's incoming webhook it will automatically notify the user (icon will popup) without refreshing the page..