Create TagCreating event for generating notifications upon creation of a tag
ADD
app/Events/TagCreating.php
+<?php
+
+namespace App\Events;
+
+use App\Notification;
+use App\Tag;
+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 TagCreating {
+ use Dispatchable, InteractsWithSockets, SerializesModels;
+
+ public function __construct(Tag $tag) {
+ Notification::create([
+ 'space_id' => $tag->space_id,
+ 'action' => 'tag.created'
+ ]);
+ }
+}

MODIFY
app/Notification.php
app/Notification.php
@@ -5,6 +5,8 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
class Notification extends Model {
+ protected $fillable = ['space_id', 'action'];
+
public function space() {
return $this->belongsTo(Space::class);
}

MODIFY
app/Tag.php
app/Tag.php
namespace App;
+use App\Events\TagCreating;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -12,6 +13,10 @@ class Tag extends Model {
protected $fillable = ['space_id', 'name'];
+ protected $dispatchesEvents = [
+ 'creating' => TagCreating::class
+ ];
+
public function spendings() {
return $this->hasMany(Spending::class);
}

Create TagCreating event for generating notifications upon creation of a tag