Я использую Laravel 5.7 для своего бэкэнда (я новичок в Laravel) и пытаюсь использовать Расширение push-уведомлений Expo для Laravel для отправки уведомлений своим пользователям.
Я следовал объясненным шагам, но не понял, где я должен разместить class ExpoNotification extends Notification и как его вызвать.
Я ожидаю, что каждый раз, когда статус заказа изменится, пользователю будет отправлено уведомление.
Что происходит, так это то, что я получаю сообщение об ошибке, говорящее, что class не может быть найден.
Контроллер заказов
public function update_order(Request $request, $id)
{
//Get the Order and update the status
Order::where('id', '=', $id )->update($request->only(['status']));
//Get the order with ::find so I can use $order->
$order = Order::find($id);
//Get user belonging to this order
$user= User::where('id', '=', $order->user_id);
//Get response with orders only posted the same day and are payed
$orders = Order::where('store_id', '=', $order->store_id)
->where('day', '=', $order->day )
->where('week', '=', $order->week )
->where('year', '=', $order->year )
->where('payment_status', '=', $order->payment_status)->get();
//send expo notification so the user gets his update
new ExpoNotification($order);
//return only relevant orders to the store
return OrderResource::collection($orders);
}
ExpoNotification
<?
namespace App\Notifications\ExpoNotification;
use App\Order;
use App\User;
use NotificationChannels\ExpoPushNotifications\ExpoChannel;
use NotificationChannels\ExpoPushNotifications\ExpoMessage;
use Illuminate\Notifications\Notification;
class ExpoNotification extends Notification
{
public function via($notifiable)
{
return [ExpoChannel::class];
}
public function toExpoPush($notifiable)
{
return ExpoMessage::create()
->badge(1)
->enableSound()
->body("Your {$notifiable->service} account was approved!");
}
}
Ошибка от почтальона
<!DOCTYPE html><!--
Symfony\Component\Debug\Exception\FatalThrowableError: Class 'App\Notifications\ExpoNotification' not found in file /Users/salmanmohamed/Documents/apps/rapiobackend/app/Http/Controllers/OrderController.php on line 182
Stack trace:
1. Symfony\Component\Debug\Exception\FatalThrowableError->() /Users/salmanmohamed/Documents/apps/rapiobackend/app/Http/Controllers/OrderController.php:182
Отвечать Предоставлено Мохаммедом
<?php
namespace App\Notifications;
use App\Order;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use NotificationChannels\ExpoPushNotifications\ExpoChannel;
use NotificationChannels\ExpoPushNotifications\ExpoMessage;
class ExNotification extends Notification
{
use Queueable;
protected $order;
public function __construct($order){
$this->order=$order;
}
public function via($notifiable)
{
return [ExpoChannel::class];
}
public function toExpoPush($notifiable)
{
return ExpoMessage::create()
->badge(1)
->enableSound()
->body("Your {$notifiable->service} account was approved!");
}
public function toArray($notifiable)
{
return [
//
];
}
}






Ваша ошибка в реализации вашего класса ExpoNotification, его пространство имен App\Expo, и вы используете App\Notifications\ExpoNotification
Спасибо за ваш ответ, изменение namespace все еще дает мне ту же ошибку. Class 'App\Notifications\ExpoNotification' not found in file /Users/salmanmohamed/Documents/apps/rapiobackend/app/Http/Controllers/OrderController.php on line 188
у вас есть anydesk или team viewer?
Да, в любом случае написать мне в директ?
Пожалуйста, пришлите мне свой идентификатор Team Viewer
привет, я следил за всем процессом, но до сих пор не получил никаких push-уведомлений, может ли кто-нибудь помочь?
привет, ты получил push-уведомление?
Как вы получили Push-токен после миграции и использовали его при отправке уведомления на конкретное устройство? Я не могу понять, как это сделать, и предоставленный код не содержит ссылок на какие-либо ключи... спасибо