Я хочу сделать уведомление, когда user2 утверждает запрос на добавление в друзья от user1. так что пользователь 1 получает уведомление. Это мой код, но результат 500 ошибок.
Уведомление:
private $sender;
private $current;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($sender, $current)
{
$this->sender = $sender;
$this->current = $current;
}
public function toDatabase($notifiable)
{
return [
'sender' => $this->sender,
'message' => 'Your friend request has been accepted.',
'currentTime' => $this->current
];
}
Контроллер:
public function acceptFriendRequest($id)
{
$sender = User::findOrFail($id);
Auth::user()->acceptFriendRequest($sender);
$current = Carbon::now();
$current = new Carbon();
User::findOrFail($id)->notify(new FriendRequestAccepted());
}
Мой Vue Компонент:
acceptfr: function (id) {
axios.post("/friend-request-accept/" + id)
.then(function (response) {
console.log("Accept FR Success");
})
.catch(function (error) {
console.log(error);
});
},
Маршрут:
Route::post('/friend-request-accept/{id}', 'FriendshipController@acceptFriendRequest');
в консоли браузера:
Error: Request failed with status code 500
at createError (app.js:653)
at settle (app.js:899)
at XMLHttpRequest.handleLoad (app.js:166)
Примечание. Все работает, если не используется уведомление.