Skip to content

Commit

Permalink
Merge pull request #7 from SethSharp/add-missing-relationships-on-Lik…
Browse files Browse the repository at this point in the history
…e-model

[2.x] - Add missing Like relationships to User and Blog
  • Loading branch information
SethSharp authored Jun 18, 2024
2 parents fdcad41 + 8b13c86 commit 1454b16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
- With the changes from [PR#5](https://github.com/SethSharp/BlogCrud/pull/5), I suggest writing a command going through all blog comments then update the comment relationship column `blog_id` to the current blog... then drop `blog_comments`
- With the changes from [PR#6](https://github.com/SethSharp/BlogCrud/pull/6), it renames the `blog_likes` table to just `likes` so relationship `likedBlogs()` on the User table is now `likes()` - and now `hasMany`. Since the relationships from the Like model has changed between the Blog and User model (to HasMany) you will need to replace any `attach` or `detach` with `create()`

## V2.0.1
- Adds missing relationships on Like Model [Pull Request #7](https://github.com/SethSharp/BlogCrud/pull/7)

## V2.0
- Moves File to proper location under `Models/Blog/` [Pull Request #3](https://github.com/SethSharp/BlogCrud/pull/3)
- Add missing size rules in requests [Pull Request #4](https://github.com/SethSharp/BlogCrud/pull/4)
Expand Down
11 changes: 11 additions & 0 deletions src/Models/Blog/Like.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SethSharp\BlogCrud\Models\Blog;

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

class Like extends Model
Expand All @@ -12,4 +13,14 @@ class Like extends Model
protected $dispatchesEvents = [
'created' => LikeCreatedEvent::class
];

public function blog(): BelongsTo
{
return $this->belongsTo(config('blog-crud.models.blog.blog'));
}

public function user(): BelongsTo
{
return $this->belongsTo(config('blog-crud.models.iam.user'));
}
}

0 comments on commit 1454b16

Please sign in to comment.