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.
50 lines
955 B
PHP
50 lines
955 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Community extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'slug',
|
|
'description',
|
|
'created_by',
|
|
];
|
|
|
|
protected static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
static::creating(function ($community) {
|
|
if (empty($community->slug)) {
|
|
$community->slug = Str::slug($community->name);
|
|
}
|
|
});
|
|
}
|
|
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public function subscribers()
|
|
{
|
|
return $this->belongsToMany(User::class)->withTimestamps();
|
|
}
|
|
|
|
public function posts()
|
|
{
|
|
return $this->hasMany(Post::class);
|
|
}
|
|
|
|
public function getRouteKeyName()
|
|
{
|
|
return 'slug';
|
|
}
|
|
}
|