Я пытаюсь создать пользовательский помощник, в локальной среде он работает отлично. но когда pu sh на сервер, я больше не могу войти, всегда возвращается страница с истекшим сроком действия.
Я пробовал 2 варианта загрузки помощников:
- требуется в поставщик услуг (функция регистрации)
public function register()
{
foreach (glob(app_path() . '/Helpers/*.php') as $file) {
require_once $file;
}
}
composer. json file
"autoload": {
...
"files": [
"app/Helpers/custom_helpers.php"
]
}
но всегда одна и та же ошибка. Laravel 7 поддерживает пользовательские помощники, если да, как их реализовать?
Это пользовательский помощник
<?php
use LaravelFCM\Facades\FCM;
use LaravelFCM\Message\OptionsBuilder;
use LaravelFCM\Message\PayloadDataBuilder;
use LaravelFCM\Message\PayloadNotificationBuilder;
if (!function_exists('push_notification')) {
/**
* Push notification
*
* @param string $device_type Device Type
* @param string $push_title Push Notification Title
* @param string $push_text Push Notification Text
* @param array $data Array of data for the push notification
* @param srting $device_id Device Id for the push notification
* @return LaravelFCM\Response\downstreamResponse Notification for the device
*/
function push_notification($device_type = 1, $push_title, $push_text, $data, $device_id) {
if ($device_type == 2) {
push_notification_ios($push_title, $push_text, $data, $device_id);
} else {
push_notification_android($push_title, $push_text, $data, $device_id);
}
}
}
if (!function_exists('push_notification_android')) {
/**
* Push notification for Android
*
* @param string $push_title Push Notification Title
* @param array $data Array of data for the push notification
* @param srting $device_id Device Id for the push notification
* @return LaravelFCM\Response\downstreamResponse Notification for the device
*/
function push_notification_android($push_title, $push_text, $data, $device_id) {
$notificationBuilder = new PayloadNotificationBuilder($push_title);
$notificationBuilder->setTitle(push_title)->setBody($push_text);
// $data['title'] = $push_title;
$data['click_action'] = 'FLUTTER_NOTIFICATION_CLICK';
$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['commande' => $data]);
$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(15);
// if ($is_background) {
// $notification = null;
// } else {
$notification = $notificationBuilder->build();
// }
$data = $dataBuilder->build();
$option = $optionBuilder->build();
try {
$downstreamResponse = FCM::sendTo($device_id, $option, $notification, $data);
} catch (\Exception $e) {
\Log::info("Push notification exception: " . $e->getMessage());
}
// \Log::info("Push notification Sent android".print_r($downstreamResponse,true));
}
}
if (!function_exists('push_notification_ios')) {
/**
* Push notification for iOS
*
* @param string $push_title Push Notification Title
* @param array $data Array of data for the push notification
* @param string $user_type User Type
* @param srting $device_id Device Id for the push notification
* @return LaravelFCM\Response\downstreamResponse Notification for the device
*/
function push_notification_ios($push_title, $push_text, $data, $device_id) {
$notificationBuilder = new PayloadNotificationBuilder($push_title);
$notificationBuilder->setBody($push_text)->setSound('default');
$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['custom' => $data]);
$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(15);
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();
$option = $optionBuilder->build();
try {
$downstreamResponse = FCM::sendTo($device_id, $option, $notification, $data);
} catch (\Exception $e) {
\Log::info("Push notification exception: " . $e->getMessage());
}
\Log::info("Push notification Sent ios");
}
}