Add events for creating and deleting transactions
MODIFY
app/Earning.php
app/Earning.php
namespace App;
+use App\Events\TransactionCreating;
+use App\Events\TransactionDeleting;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -12,6 +14,11 @@ class Earning extends Model {
protected $fillable = ['happened_on', 'description', 'amount'];
+ protected $dispatchesEvents = [
+ 'creating' => TransactionCreating::class,
+ 'deleting' => TransactionDeleting::class
+ ];
+
// Accessors
public function getFormattedAmountAttribute() {
return number_format($this->amount / 100, 2);

ADD
app/Events/TransactionCreating.php
+<?php
+
+namespace App\Events;
+
+use App\Notification;
+use Illuminate\Broadcasting\Channel;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Broadcasting\PrivateChannel;
+use Illuminate\Broadcasting\PresenceChannel;
+use Illuminate\Foundation\Events\Dispatchable;
+use Illuminate\Broadcasting\InteractsWithSockets;
+use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
+
+class TransactionCreating {
+ use Dispatchable, InteractsWithSockets, SerializesModels;
+
+ public function __construct($transaction) {
+ Notification::create([
+ 'space_id' => $transaction->space_id,
+ 'user_id' => \Auth::user()->id,
+ 'action' => 'transaction.created'
+ ]);
+ }
+}

ADD
app/Events/TransactionDeleting.php
+<?php
+
+namespace App\Events;
+
+use App\Notification;
+use Illuminate\Broadcasting\Channel;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Broadcasting\PrivateChannel;
+use Illuminate\Broadcasting\PresenceChannel;
+use Illuminate\Foundation\Events\Dispatchable;
+use Illuminate\Broadcasting\InteractsWithSockets;
+use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
+
+class TransactionDeleting {
+ use Dispatchable, InteractsWithSockets, SerializesModels;
+
+ public function __construct($transaction) {
+ Notification::create([
+ 'space_id' => $transaction->space_id,
+ 'user_id' => \Auth::user()->id,
+ 'action' => 'transaction.deleted'
+ ]);
+ }
+}

MODIFY
app/Spending.php
app/Spending.php
namespace App;
+use App\Events\TransactionCreating;
+use App\Events\TransactionDeleting;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -19,6 +21,11 @@ class Spending extends Model {
'amount'
];
+ protected $dispatchesEvents = [
+ 'creating' => TransactionCreating::class,
+ 'deleting' => TransactionDeleting::class
+ ];
+
// Accessors
public function getFormattedAmountAttribute() {
return number_format($this->amount / 100, 2);

Add events for creating and deleting transactions