mirror of
https://github.com/m1ngsama/php.git
synced 2025-12-24 16:01:19 +00:00
Added Community, Post, Comment, and Vote models with proper relationships. Updated User model to include karma field and forum-related relationships.
53 lines
941 B
PHP
53 lines
941 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Post extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'community_id',
|
|
'user_id',
|
|
'title',
|
|
'content',
|
|
'url',
|
|
'type',
|
|
'votes',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'votes' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function community()
|
|
{
|
|
return $this->belongsTo(Community::class);
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function comments()
|
|
{
|
|
return $this->hasMany(Comment::class);
|
|
}
|
|
|
|
public function votes()
|
|
{
|
|
return $this->morphMany(Vote::class, 'voteable');
|
|
}
|
|
|
|
public function userVote($userId)
|
|
{
|
|
return $this->votes()->where('user_id', $userId)->first();
|
|
}
|
|
}
|