Browse Source

some bug fix in socket, some change in notif helper, add notif controller

master
mahdihty 4 years ago
parent
commit
db23f3c423
  1. 17
      app/Channels/SocketChannel.php
  2. 22
      app/Http/Controllers/NotificationController.php
  3. 5
      app/Notifications/DBNotification.php
  4. 11
      app/Utilities/HelperClass/NotificationHelper.php
  5. 299
      composer.lock
  6. 1
      database/migrations/2021_03_08_114700_create_notifications_table.php
  7. 1
      docker-compose.yml
  8. 7
      routes/api.php

17
app/Channels/SocketChannel.php

@ -51,11 +51,16 @@ class SocketChannel
return;
}
$this->http->post($this->socket_url . '/emit/' . $message->to, [
'headers' => [
'Content-Type' => 'application/json',
],
'json' => ['data' => $message->data],
]);
try {
$this->http->post($this->socket_url . '/emit/' . $message->to, [
'headers' => [
'Content-Type' => 'application/json',
],
'json' => ['data' => $message->data],
]);
} catch (\GuzzleHttp\Exception\ConnectException $e) {
report($e);
}
}
}

22
app/Http/Controllers/NotificationController.php

@ -0,0 +1,22 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class NotificationController extends Controller
{
public function index($business)
{
return Auth::user()->notifications()->where('business_id', $business)->get();
}
public function markAsRead($business, $notification)
{
return Auth::user()->unreadNotifications()
->where('business_id', $business)
->findOrFail($notification)
->markAsRead();
}
}

5
app/Notifications/DBNotification.php

@ -3,8 +3,6 @@
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class DBNotification extends Notification
@ -43,7 +41,8 @@ class DBNotification extends Notification
public function toArray($notifiable)
{
return [
'data' => $this->message['body']
'data' => $this->message['body'],
'business_id' => 1
];
}
}

11
app/Utilities/HelperClass/NotificationHelper.php

@ -7,6 +7,7 @@ namespace App\Utilities\HelperClass;
use App\Notifications\DBNotification;
use App\Notifications\FcmNotification;
use App\Notifications\MailNotification;
use App\Notifications\SocketNotification;
use Illuminate\Support\Facades\Notification;
class NotificationHelper
@ -56,16 +57,16 @@ class NotificationHelper
case "emergency":
// Notification::send($users, new SmsNotification($notif));
case "critical":
Notification::send($users, new MailNotification($notif));
Notification::send($users, new MailNotification($this->notif));
case "high":
Notification::send($users, new DBNotification($notif));
Notification::send($users, new DBNotification($this->notif));
case "medium":
Notification::send($users, new FcmNotification($notif));
Notification::send($users, new FcmNotification($this->notif));
case "low":
Notification::send($users, new SocketNotification($notif));
Notification::send($users, new SocketNotification($this->notif));
break;
default:
Notification::send($users, new SocketNotification($notif));
Notification::send($users, new SocketNotification($this->notif));
}
}

299
composer.lock

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "5bd413ba3541289df0ed987c8c36efb7",
"content-hash": "ad69869827abcf682bf25c0728bb8eed",
"packages": [
{
"name": "anik/amqp",
@ -63,16 +63,16 @@
},
{
"name": "asm89/stack-cors",
"version": "v2.0.2",
"version": "v2.0.3",
"source": {
"type": "git",
"url": "https://github.com/asm89/stack-cors.git",
"reference": "8d8f88b3b3830916be94292c1fbce84433efb1aa"
"reference": "9cb795bf30988e8c96dd3c40623c48a877bc6714"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/asm89/stack-cors/zipball/8d8f88b3b3830916be94292c1fbce84433efb1aa",
"reference": "8d8f88b3b3830916be94292c1fbce84433efb1aa",
"url": "https://api.github.com/repos/asm89/stack-cors/zipball/9cb795bf30988e8c96dd3c40623c48a877bc6714",
"reference": "9cb795bf30988e8c96dd3c40623c48a877bc6714",
"shasum": ""
},
"require": {
@ -113,22 +113,22 @@
],
"support": {
"issues": "https://github.com/asm89/stack-cors/issues",
"source": "https://github.com/asm89/stack-cors/tree/v2.0.2"
"source": "https://github.com/asm89/stack-cors/tree/v2.0.3"
},
"time": "2020-10-29T16:03:21+00:00"
"time": "2021-03-11T06:42:03+00:00"
},
{
"name": "aws/aws-sdk-php",
"version": "3.173.25",
"version": "3.173.28",
"source": {
"type": "git",
"url": "https://github.com/aws/aws-sdk-php.git",
"reference": "69e4653acf8cd855e9010ec4e0e0a7d074c77ee1"
"reference": "593baa5930896bb443c437032daf4016e1e3878d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/69e4653acf8cd855e9010ec4e0e0a7d074c77ee1",
"reference": "69e4653acf8cd855e9010ec4e0e0a7d074c77ee1",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/593baa5930896bb443c437032daf4016e1e3878d",
"reference": "593baa5930896bb443c437032daf4016e1e3878d",
"shasum": ""
},
"require": {
@ -203,9 +203,9 @@
"support": {
"forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
"issues": "https://github.com/aws/aws-sdk-php/issues",
"source": "https://github.com/aws/aws-sdk-php/tree/3.173.25"
"source": "https://github.com/aws/aws-sdk-php/tree/3.173.28"
},
"time": "2021-03-09T19:14:56+00:00"
"time": "2021-03-12T19:29:55+00:00"
},
{
"name": "beberlei/assert",
@ -870,6 +870,64 @@
],
"time": "2020-04-13T13:17:36+00:00"
},
{
"name": "graylog2/gelf-php",
"version": "1.7.0",
"source": {
"type": "git",
"url": "https://github.com/bzikarsky/gelf-php.git",
"reference": "16cab667fa01e6e298af1ec3279fe08d43e40a96"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bzikarsky/gelf-php/zipball/16cab667fa01e6e298af1ec3279fe08d43e40a96",
"reference": "16cab667fa01e6e298af1ec3279fe08d43e40a96",
"shasum": ""
},
"require": {
"paragonie/constant_time_encoding": "^1|^2",
"php": ">=5.6",
"psr/log": "~1.0"
},
"provide": {
"psr/log-implementation": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7|^6.5|^7.5",
"squizlabs/php_codesniffer": "^3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
}
},
"autoload": {
"psr-4": {
"Gelf\\": "src/Gelf"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Benjamin Zikarsky",
"email": "benjamin@zikarsky.de"
},
{
"name": "gelf-php contributors",
"homepage": "https://github.com/bzikarsky/gelf-php/contributors"
}
],
"description": "A php implementation to send log-messages to a GELF compatible backend like Graylog2.",
"support": {
"issues": "https://github.com/bzikarsky/gelf-php/issues",
"source": "https://github.com/bzikarsky/gelf-php/tree/1.7.0"
},
"time": "2021-02-04T09:05:55+00:00"
},
{
"name": "guzzlehttp/guzzle",
"version": "7.2.0",
@ -1102,6 +1160,63 @@
},
"time": "2020-09-30T07:37:11+00:00"
},
{
"name": "hedii/laravel-gelf-logger",
"version": "6.0.0",
"source": {
"type": "git",
"url": "https://github.com/hedii/laravel-gelf-logger.git",
"reference": "231f6dfc41546bfe5e1e02bc85f98d0d5db811c1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hedii/laravel-gelf-logger/zipball/231f6dfc41546bfe5e1e02bc85f98d0d5db811c1",
"reference": "231f6dfc41546bfe5e1e02bc85f98d0d5db811c1",
"shasum": ""
},
"require": {
"graylog2/gelf-php": "^1.6",
"illuminate/log": "^8.12",
"php": "^7.3|^8.0"
},
"require-dev": {
"orchestra/testbench": "^6.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Hedii\\LaravelGelfLogger\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "hedii",
"homepage": "https://hedichaibi.com"
}
],
"description": "A Laravel package to send logs to a gelf compatible backend like graylog",
"keywords": [
"gelf",
"graylog",
"graylog2",
"hedii",
"laravel",
"laravel-gelf",
"log",
"logging",
"php",
"udp"
],
"support": {
"issues": "https://github.com/hedii/laravel-gelf-logger/issues",
"source": "https://github.com/hedii/laravel-gelf-logger"
},
"time": "2020-11-30T09:39:06+00:00"
},
{
"name": "intervention/image",
"version": "2.5.1",
@ -2845,6 +2960,73 @@
},
"time": "2020-11-07T02:01:34+00:00"
},
{
"name": "paragonie/constant_time_encoding",
"version": "v2.4.0",
"source": {
"type": "git",
"url": "https://github.com/paragonie/constant_time_encoding.git",
"reference": "f34c2b11eb9d2c9318e13540a1dbc2a3afbd939c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/f34c2b11eb9d2c9318e13540a1dbc2a3afbd939c",
"reference": "f34c2b11eb9d2c9318e13540a1dbc2a3afbd939c",
"shasum": ""
},
"require": {
"php": "^7|^8"
},
"require-dev": {
"phpunit/phpunit": "^6|^7|^8|^9",
"vimeo/psalm": "^1|^2|^3|^4"
},
"type": "library",
"autoload": {
"psr-4": {
"ParagonIE\\ConstantTime\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paragon Initiative Enterprises",
"email": "security@paragonie.com",
"homepage": "https://paragonie.com",
"role": "Maintainer"
},
{
"name": "Steve 'Sc00bz' Thomas",
"email": "steve@tobtu.com",
"homepage": "https://www.tobtu.com",
"role": "Original Developer"
}
],
"description": "Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)",
"keywords": [
"base16",
"base32",
"base32_decode",
"base32_encode",
"base64",
"base64_decode",
"base64_encode",
"bin2hex",
"encoding",
"hex",
"hex2bin",
"rfc4648"
],
"support": {
"email": "info@paragonie.com",
"issues": "https://github.com/paragonie/constant_time_encoding/issues",
"source": "https://github.com/paragonie/constant_time_encoding"
},
"time": "2020-12-06T15:14:20+00:00"
},
{
"name": "php-amqplib/php-amqplib",
"version": "v2.12.1",
@ -3459,16 +3641,16 @@
},
{
"name": "psy/psysh",
"version": "v0.10.6",
"version": "v0.10.7",
"source": {
"type": "git",
"url": "https://github.com/bobthecow/psysh.git",
"reference": "6f990c19f91729de8b31e639d6e204ea59f19cf3"
"reference": "a395af46999a12006213c0c8346c9445eb31640c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bobthecow/psysh/zipball/6f990c19f91729de8b31e639d6e204ea59f19cf3",
"reference": "6f990c19f91729de8b31e639d6e204ea59f19cf3",
"url": "https://api.github.com/repos/bobthecow/psysh/zipball/a395af46999a12006213c0c8346c9445eb31640c",
"reference": "a395af46999a12006213c0c8346c9445eb31640c",
"shasum": ""
},
"require": {
@ -3529,9 +3711,9 @@
],
"support": {
"issues": "https://github.com/bobthecow/psysh/issues",
"source": "https://github.com/bobthecow/psysh/tree/v0.10.6"
"source": "https://github.com/bobthecow/psysh/tree/v0.10.7"
},
"time": "2021-01-18T15:53:43+00:00"
"time": "2021-03-14T02:14:56+00:00"
},
{
"name": "ralouphie/getallheaders",
@ -3748,20 +3930,21 @@
},
{
"name": "spatie/image",
"version": "1.10.2",
"version": "1.10.4",
"source": {
"type": "git",
"url": "https://github.com/spatie/image.git",
"reference": "12662673fbe649bffcd3a24188a404dc31fa118c"
"reference": "7ea129bc7b7521864c5a540e3b1c14ea194316d3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/image/zipball/12662673fbe649bffcd3a24188a404dc31fa118c",
"reference": "12662673fbe649bffcd3a24188a404dc31fa118c",
"url": "https://api.github.com/repos/spatie/image/zipball/7ea129bc7b7521864c5a540e3b1c14ea194316d3",
"reference": "7ea129bc7b7521864c5a540e3b1c14ea194316d3",
"shasum": ""
},
"require": {
"ext-exif": "*",
"ext-json": "*",
"ext-mbstring": "*",
"league/glide": "^1.6",
"php": "^7.2|^8.0",
@ -3771,7 +3954,8 @@
},
"require-dev": {
"phpunit/phpunit": "^8.0|^9.0",
"symfony/var-dumper": "^4.0|^5.0"
"symfony/var-dumper": "^4.0|^5.0",
"vimeo/psalm": "^4.6"
},
"type": "library",
"autoload": {
@ -3799,7 +3983,7 @@
],
"support": {
"issues": "https://github.com/spatie/image/issues",
"source": "https://github.com/spatie/image/tree/1.10.2"
"source": "https://github.com/spatie/image/tree/1.10.4"
},
"funding": [
{
@ -3811,7 +3995,7 @@
"type": "github"
}
],
"time": "2021-01-26T07:53:19+00:00"
"time": "2021-03-10T16:11:40+00:00"
},
{
"name": "spatie/image-optimizer",
@ -4169,16 +4353,16 @@
},
{
"name": "symfony/console",
"version": "v5.2.4",
"version": "v5.2.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "d6d0cc30d8c0fda4e7b213c20509b0159a8f4556"
"reference": "938ebbadae1b0a9c9d1ec313f87f9708609f1b79"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/d6d0cc30d8c0fda4e7b213c20509b0159a8f4556",
"reference": "d6d0cc30d8c0fda4e7b213c20509b0159a8f4556",
"url": "https://api.github.com/repos/symfony/console/zipball/938ebbadae1b0a9c9d1ec313f87f9708609f1b79",
"reference": "938ebbadae1b0a9c9d1ec313f87f9708609f1b79",
"shasum": ""
},
"require": {
@ -4246,7 +4430,7 @@
"terminal"
],
"support": {
"source": "https://github.com/symfony/console/tree/v5.2.4"
"source": "https://github.com/symfony/console/tree/v5.2.5"
},
"funding": [
{
@ -4262,7 +4446,7 @@
"type": "tidelift"
}
],
"time": "2021-02-23T10:08:49+00:00"
"time": "2021-03-06T13:42:15+00:00"
},
{
"name": "symfony/css-selector",
@ -4844,16 +5028,16 @@
},
{
"name": "symfony/http-kernel",
"version": "v5.2.4",
"version": "v5.2.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/http-kernel.git",
"reference": "c452dbe4f385f030c3957821bf921b13815d6140"
"reference": "b8c63ef63c2364e174c3b3e0ba0bf83455f97f73"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/http-kernel/zipball/c452dbe4f385f030c3957821bf921b13815d6140",
"reference": "c452dbe4f385f030c3957821bf921b13815d6140",
"url": "https://api.github.com/repos/symfony/http-kernel/zipball/b8c63ef63c2364e174c3b3e0ba0bf83455f97f73",
"reference": "b8c63ef63c2364e174c3b3e0ba0bf83455f97f73",
"shasum": ""
},
"require": {
@ -4936,7 +5120,7 @@
"description": "Provides a structured process for converting a Request into a Response",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/http-kernel/tree/v5.2.4"
"source": "https://github.com/symfony/http-kernel/tree/v5.2.5"
},
"funding": [
{
@ -4952,20 +5136,20 @@
"type": "tidelift"
}
],
"time": "2021-03-04T18:05:55+00:00"
"time": "2021-03-10T17:07:35+00:00"
},
{
"name": "symfony/mime",
"version": "v5.2.4",
"version": "v5.2.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/mime.git",
"reference": "5155d2fe14ef1eb150e3bdbbc1ec1455df95e9cd"
"reference": "554ba128f1955038b45db5e1fa7e93bfc683b139"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/mime/zipball/5155d2fe14ef1eb150e3bdbbc1ec1455df95e9cd",
"reference": "5155d2fe14ef1eb150e3bdbbc1ec1455df95e9cd",
"url": "https://api.github.com/repos/symfony/mime/zipball/554ba128f1955038b45db5e1fa7e93bfc683b139",
"reference": "554ba128f1955038b45db5e1fa7e93bfc683b139",
"shasum": ""
},
"require": {
@ -4976,12 +5160,13 @@
"symfony/polyfill-php80": "^1.15"
},
"conflict": {
"egulias/email-validator": "~3.0.0",
"phpdocumentor/reflection-docblock": "<3.2.2",
"phpdocumentor/type-resolver": "<1.4.0",
"symfony/mailer": "<4.4"
},
"require-dev": {
"egulias/email-validator": "^2.1.10",
"egulias/email-validator": "^2.1.10|^3.1",
"phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0",
"symfony/dependency-injection": "^4.4|^5.0",
"symfony/property-access": "^4.4|^5.1",
@ -5018,7 +5203,7 @@
"mime-type"
],
"support": {
"source": "https://github.com/symfony/mime/tree/v5.2.4"
"source": "https://github.com/symfony/mime/tree/v5.2.5"
},
"funding": [
{
@ -5034,7 +5219,7 @@
"type": "tidelift"
}
],
"time": "2021-02-15T18:55:04+00:00"
"time": "2021-03-07T16:08:20+00:00"
},
{
"name": "symfony/polyfill-ctype",
@ -6081,16 +6266,16 @@
},
{
"name": "symfony/translation",
"version": "v5.2.4",
"version": "v5.2.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/translation.git",
"reference": "74b0353ab34ff4cca827a2cf909e325d96815e60"
"reference": "0947ab1e3aabd22a6bef393874b2555d2bb976da"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/translation/zipball/74b0353ab34ff4cca827a2cf909e325d96815e60",
"reference": "74b0353ab34ff4cca827a2cf909e325d96815e60",
"url": "https://api.github.com/repos/symfony/translation/zipball/0947ab1e3aabd22a6bef393874b2555d2bb976da",
"reference": "0947ab1e3aabd22a6bef393874b2555d2bb976da",
"shasum": ""
},
"require": {
@ -6154,7 +6339,7 @@
"description": "Provides tools to internationalize your application",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/translation/tree/v5.2.4"
"source": "https://github.com/symfony/translation/tree/v5.2.5"
},
"funding": [
{
@ -6170,7 +6355,7 @@
"type": "tidelift"
}
],
"time": "2021-03-04T15:41:09+00:00"
"time": "2021-03-06T07:59:01+00:00"
},
{
"name": "symfony/translation-contracts",
@ -6252,16 +6437,16 @@
},
{
"name": "symfony/var-dumper",
"version": "v5.2.4",
"version": "v5.2.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/var-dumper.git",
"reference": "6a81fec0628c468cf6d5c87a4d003725e040e223"
"reference": "002ab5a36702adf0c9a11e6d8836623253e9045e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/var-dumper/zipball/6a81fec0628c468cf6d5c87a4d003725e040e223",
"reference": "6a81fec0628c468cf6d5c87a4d003725e040e223",
"url": "https://api.github.com/repos/symfony/var-dumper/zipball/002ab5a36702adf0c9a11e6d8836623253e9045e",
"reference": "002ab5a36702adf0c9a11e6d8836623253e9045e",
"shasum": ""
},
"require": {
@ -6320,7 +6505,7 @@
"dump"
],
"support": {
"source": "https://github.com/symfony/var-dumper/tree/v5.2.4"
"source": "https://github.com/symfony/var-dumper/tree/v5.2.5"
},
"funding": [
{
@ -6336,7 +6521,7 @@
"type": "tidelift"
}
],
"time": "2021-02-18T23:11:19+00:00"
"time": "2021-03-06T07:59:01+00:00"
},
{
"name": "tijsverkoyen/css-to-inline-styles",

1
database/migrations/2021_03_08_114700_create_notifications_table.php

@ -17,6 +17,7 @@ class CreateNotificationsTable extends Migration
$table->uuid('id')->primary();
$table->string('type');
$table->morphs('notifiable');
$table->unsignedBigInteger('business_id');
$table->text('data');
$table->timestamp('read_at')->nullable();
$table->timestamps();

1
docker-compose.yml

@ -115,6 +115,7 @@ services:
networks:
- hi-user
elasticsearch:
container_name: "elastic"
image: docker.elastic.co/elasticsearch/elasticsearch:7.11.2
environment:
- http.host=0.0.0.0

7
routes/api.php

@ -2,6 +2,10 @@
/** @var \Illuminate\Routing\$router */
$router->get('/lab', function () {
throw new \Exception("^_^");
});
$router->get('/ntest', function () {
$user = \App\Models\User::find(1);
\Illuminate\Support\Facades\Notification::send($user, new \App\Notifications\SocketNotification(['title' => "hello!!!", 'body' => 'sss']));
@ -43,6 +47,9 @@ $router->group(['prefix' => 'businesses', 'middleware' => 'auth:api'], function
$router->group(['prefix' => '{business}', 'middleware' => 'bindBusiness'], function () use ($router) {
$router->get('/notifications', 'NotificationController@index');
$router->get('/notifications/{notification}/read', 'NotificationController@markAsRead');
$router->get('/tasks', 'TaskController@index');
$router->get('/works', 'WorkController@index');
$router->get('statistics', 'StatisticController@index');

Loading…
Cancel
Save