問題があります。 私はリアルタイム通知のプッシャーを使用しています。実行するとnotyを使用して私に通知します。 しかし、私はリアルタイムで新しい通知の番号をFacebookに似たように表示します。リアルタイムlaravel5.2、vue.js、プッシャーでデータを取得する
<span class="label label-warning" v-show="new_count">@{{ new_count }}<!-- get the new notifications --></span>
どうすればよいですか?
これは私のコードです。
nav.js
new Vue({
el: '#nav',
data: {
new_count: 0
},
methods: {
getNewCount: function() {
this.$http.get('cron', function(new_count){
console.log(new_count);
this.new_count = new_count;
}.bind(this));
}
}
});
cronジョブコントローラ。この方法は毎分実行されます。
class CronJobController extends Controller
{
public function getIndex()
{
$old_fail_notification = FailNotification::where('seen', 0)->count();
$subjects_with_fail = Grade::where('grade', 'F')->groupBy('subject_id')->orderBy('subject_id', 'ASC')->get();
return response()->json(['new_count' => 2]); //send this to navbar
foreach ($subjects_with_fail as $subject) {
$subject_to_check = Grade::where('grade', 'F')->where('subject_id', $subject->subject_id)->where('reviewed', '0')->get(); //add if grade is IC or D
if (count($subject_to_check) >= 3) {
$failed = new FailNotification();
$failed->message = '[subject-'.$subject->subject_id.'] can now be opened.';
$failed->save();
foreach ($subject_to_check as $subject) {
$subject = Grade::find($subject->id);
$subject->reviewed = 1;
$subject->save();
}
}
}
$fail_notification = FailNotification::all()->count();
//UPDATE NOTIFICATION COUNT HERE REAL TIME USING AJAX
if ($fail_notification > $old_fail_notification) {
$new_notification_count = $fail_notification - $old_fail_notification;
Pusher::trigger('test-channel', 'test-event', [
'name' => 'You have a new',
'message' => 'Notification'
]);
Pusher::trigger('navbar-channel', 'navbar-event', [
'new_notif_count' => $new_notification_count,
]);
return response()->json(['new_count' => $new_notification_count]); //send this to navbar
}
}
}
私が間違ってやっていると私はそれが正しいどのように行うのか何を教えてください。
そして、あなたがに加入していますプッシャーサービス?以下で述べるように、vue.resourceのgetメソッドは単一のメソッドであり、プッシャーイベントを常に聞く必要があります。ドキュメントでは、彼らはあなたがsusbcirbeメソッドでそれを行うと言いますか?あなたのVueコードはどこですか?ありがとうございました! –
!私は現在、プッシャーサービスを購読しています。 –