Skip to content

Commit

Permalink
model events on Comment and Like
Browse files Browse the repository at this point in the history
  • Loading branch information
SethSharp committed May 28, 2024
1 parent 4cd8a10 commit c8b2a4f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Models/Blog/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use SethSharp\BlogCrud\Models\Events\CommentCreatedEvent;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use SethSharp\BlogCrud\Database\Factories\Domain\Blog\Models\CommentFactory;

Expand All @@ -14,6 +15,10 @@ class Comment extends Model

protected $guarded = [];

protected $dispatchesEvents = [
'created' => CommentCreatedEvent::class
];

protected static function newFactory()
{
return new CommentFactory();
Expand Down
4 changes: 4 additions & 0 deletions src/Models/Blog/Like.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
namespace SethSharp\BlogCrud\Models\Blog;

use Illuminate\Database\Eloquent\Model;
use SethSharp\BlogCrud\Models\Events\LikeCreatedEvent;

class Like extends Model
{
protected $dispatchesEvents = [
'created' => LikeCreatedEvent::class
];
}
16 changes: 16 additions & 0 deletions src/Models/Events/CommentCreatedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace SethSharp\BlogCrud\Models\Events;

use Illuminate\Support\Facades\Event;
use SethSharp\BlogCrud\Models\Blog\Comment;

class CommentCreatedEvent extends Event
{
public Comment $comment;

public function __construct(Comment $comment)
{
$this->comment = $comment;
}
}
16 changes: 16 additions & 0 deletions src/Models/Events/LikeCreatedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace SethSharp\BlogCrud\Models\Events;

use Illuminate\Support\Facades\Event;
use SethSharp\BlogCrud\Models\Blog\Like;

class LikeCreatedEvent extends Event
{
public Like $like;

public function __construct(Like $like)
{
$this->like = $like;
}
}

0 comments on commit c8b2a4f

Please sign in to comment.