feat: reviews
This commit is contained in:
@@ -49,6 +49,11 @@ class MealPosts extends Model
|
||||
return $this->hasMany(MealPostIngredients::class)->orderBy('position');
|
||||
}
|
||||
|
||||
public function reviews(): HasMany
|
||||
{
|
||||
return $this->hasMany(PostReviews::class, 'meal_post_id');
|
||||
}
|
||||
|
||||
public function likedByUsers(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'meal_post_likes', 'meal_posts_id', 'user_id')
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class PostReviews extends Model
|
||||
{
|
||||
use HasUlids;
|
||||
|
||||
protected $fillable = [
|
||||
'meal_post_id',
|
||||
'rating',
|
||||
'comment',
|
||||
'user_id',
|
||||
];
|
||||
|
||||
public function mealPost(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(MealPosts::class, 'meal_post_id');
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'id' => 'string',
|
||||
'rating' => 'integer',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user