laravel-无法标记通知
我创建了一个通知,它获取所有最新的通知,并在单击它们时将它们标记为已读 UserNotifications.vue:laravel-无法标记通知,laravel,Laravel,我创建了一个通知,它获取所有最新的通知,并在单击它们时将它们标记为已读 UserNotifications.vue: <template> <li class="nav-item dropdown" v-if="notifications.length"> <a class="nav-link" href="#" role="button" data-t
<template>
<li class="nav-item dropdown" v-if="notifications.length">
<a class="nav-link" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
<span class="fas fa-bell"></span>
</a>
<ul class="dropdown-menu">
<li v-for="notification in notifications" :key="notification.id">
<a :href="notification.data.link"
v-text="notification.data.message"
@click="markAsRead(notification)"
></a>
</li>
</ul>
</li>
</template>
<script>
export default {
data() {
return {notifications: false}
},
created() {
axios.get('/profiles/' + window.App.user.name + '/notifications')
.then(response => this.notifications = response.data);
},
methods: {
markAsRead(notification) {
axios.delete('/profiles/' + window.App.user.name + '/notifications/' + notification.id)
}
}
}
</script>
web.php:
//Get notification for user
Route::get('/profiles/{user}/notifications','UserNotificationsController@index')->name('notification.index');
//Delete notification
Route::delete('/profiles/{user}/notifcations/{notification}','UserNotificationsController@destroy')->name('notifcation.destroy');
在让未读通知工作时,但当我单击通知时,它返回一个响应错误404 not found。通知表具有正确的notificationId,但无法将其标记为已读。我不明白为什么它不能工作
在通知表中,单击未读通知后,read_at列为NULL。有人知道原因吗?看起来您的
删除路线(通知)中有一个输入错误
更新删除路由应做到以下几点:
Route::delete('/profiles/{user}/notifications/{notification}', 'UserNotificationsController@destroy')->name('notification.destroy');
请求的URL在结尾是否具有正确的通知id?@Rwd yeap,它表示DELETEhttp://forum.test/profiles/Nicholas/notifications/f6d095e2-e342-42a8-a294-0e3187c11dcb 404(未找到)
。我检查了我的通知表id,它与URL上的哈希值匹配。您是否能够通过用户使用tinker(或单独的路由)手动检索通知,例如$user->notifications()->findOrFail('f6d095e2-e342-42a8-a294-0e3187c11dcb')
?我进一步检查了失败的请求,它说:“Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException”一点也不担心。我们都去过!很高兴我能帮忙:)
Route::delete('/profiles/{user}/notifications/{notification}', 'UserNotificationsController@destroy')->name('notification.destroy');