gpt4 book ai didi

Laravel 5.7 使用 Expo 发送通知

转载 作者:行者123 更新时间:2023-12-02 19:55:12 24 4
gpt4 key购买 nike

我的后端使用 Laravel 5.7(我是 Laravel 的新手),我正在尝试使用 Expo push notification extension for Laravel向我的用户发送通知。

我按照说明的步骤进行操作,但我迷失了我应该放置 class ExpoNotification extends Notification 的位置以及如何调用它。

我希望发生的是,每次订单状态发生变化时,都会向用户发送通知。

发生的事情是我收到一条错误消息,指出找不到 class

订单 Controller

    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);
}

展会通知

<?
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!");
}
}

postman 错误

<!DOCTYPE html><!--


Symfony\Component\Debug\Exception\FatalThrowableError: Class &#039;App\Notifications\ExpoNotification&#039; 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-&gt;() /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

关于Laravel 5.7 使用 Expo 发送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57232837/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com