Allow events to be used by scheduled jobs (not as an authenticated user)
MODIFY
app/Events/TagCreated.php
app/Events/TagCreated.php
@@ -11,14 +11,21 @@ use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
+use Illuminate\Support\Facades\Auth;
class TagCreated {
use Dispatchable, InteractsWithSockets, SerializesModels;
public function __construct(Tag $tag) {
+ $userId = null;
+
+ if (Auth::check()) {
+ $userId = Auth::user()->id;
+ }
+
Notification::create([
'space_id' => $tag->space_id,
- 'user_id' => \Auth::user()->id,
+ 'user_id' => $userId,
'entity_id' => $tag->id,
'entity_type' => 'tag',
'action' => 'tag.created'

MODIFY
app/Events/TagDeleted.php
app/Events/TagDeleted.php
@@ -11,14 +11,21 @@ use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
+use Illuminate\Support\Facades\Auth;
class TagDeleted {
use Dispatchable, InteractsWithSockets, SerializesModels;
public function __construct(Tag $tag) {
+ $userId = null;
+
+ if (Auth::check()) {
+ $userId = Auth::user()->id;
+ }
+
Notification::create([
'space_id' => $tag->space_id,
- 'user_id' => \Auth::user()->id,
+ 'user_id' => $userId,
'entity_id' => $tag->id,
'entity_type' => 'tag',
'action' => 'tag.deleted'

MODIFY
app/Events/TransactionCreated.php
app/Events/TransactionCreated.php
@@ -12,11 +12,18 @@ use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
+use Illuminate\Support\Facades\Auth;
class TransactionCreated {
use Dispatchable, InteractsWithSockets, SerializesModels;
public function __construct($transaction) {
+ $userId = null;
+
+ if (Auth::check()) {
+ $userId = Auth::user()->id;
+ }
+
if ($transaction instanceof Earning) {
$entityType = 'earning';
}
@@ -27,7 +34,7 @@ class TransactionCreated {
Notification::create([
'space_id' => $transaction->space_id,
- 'user_id' => \Auth::user()->id,
+ 'user_id' => $userId,
'entity_id' => $transaction->id,
'entity_type' => $entityType,
'action' => 'transaction.created'

MODIFY
app/Events/TransactionDeleted.php
app/Events/TransactionDeleted.php
@@ -12,11 +12,18 @@ use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
+use Illuminate\Support\Facades\Auth;
class TransactionDeleted {
use Dispatchable, InteractsWithSockets, SerializesModels;
public function __construct($transaction) {
+ $userId = null;
+
+ if (Auth::check()) {
+ $userId = Auth::user()->id;
+ }
+
if ($transaction instanceof Earning) {
$entityType = 'earning';
}
@@ -27,7 +34,7 @@ class TransactionDeleted {
Notification::create([
'space_id' => $transaction->space_id,
- 'user_id' => \Auth::user()->id,
+ 'user_id' => $userId,
'entity_id' => $transaction->id,
'entity_type' => $entityType,
'action' => 'transaction.deleted'

Allow events to be used by scheduled jobs (not as an authenticated user)