first commit
This commit is contained in:
41
app/Models/Comment.php
Normal file
41
app/Models/Comment.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
//columns that are fillable in the table
|
||||
protected $fillable = [
|
||||
"content",
|
||||
'user_id',
|
||||
'post_id'
|
||||
];
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Get the post that the comment belongs to.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function post(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Post::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user that authored the comment.
|
||||
* If the user is not found, return a default guest author.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class)->withDefault([
|
||||
'name' => 'Guest Author',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user