Я пытаюсь отобразить панель уведомлений из компонента vue в layout / app.blade, но в консоли возникают ошибки.
[Vue warn]: ошибка в созданном хуке: «Ошибка типа: невозможно прочитать свойство 'userId' неопределенного"
и,
TypeError: Невозможно прочитать свойство 'userId' из неопределенного
. Мой app.js подобен приведенному ниже.
require('./bootstrap');
window.Vue = require('vue');
window._ = require('lodash');
window.$ = window.jQuery = require('jquery');
Vue.component('estate', require('./components/EstateNotification.vue'));
const app = new Vue({
el: '#app',
data: {
estates: '',
},
created(){
if (window.Laravel.userId){
axios.post('/notification/estate/notification').then(response => {
this.estates = response.data;
console.log(response.data)
});
Echo.private('App.User.'+ window.Laravel.userId).notification((response) => {
data = {"data":response};
this.estates.push(data);
console.log(response);
});
}
}
});
На моем маршруте:
Route::post('/notification/estate/notification', 'EstateController@notification');
Контроллер:
public function notification()
{
return auth()->user()->unreadNotifications;
}
Но я не мог понять, почему userId не определен?где я делаю не так?Действительно спасибо за любую помощь!