%PDF- %PDF-
Direktori : /var/www/html/news/app/Models/ |
Current File : /var/www/html/news/app/Models/Comment.php |
<?php namespace App\Models; use Laracodes\Presenter\Traits\Presentable; class Comment extends BaseModel { use Presentable; protected $presenter = CommentPresenter::class; protected $fillable = [ 'content', 'user_id', 'article_id', 'is_approved' ]; protected $casts = [ 'id' => 'integer', 'content' => 'string', 'is_approved' => 'boolean', 'user_id' => 'integer', 'article_id' => 'integer', ]; protected $dates = [ ]; public function user() { return $this->belongsTo(User::class); } public function article() { return $this->belongsTo(Article::class); } public function isAppropriate() { $words = InappropriateWord::all(); if (count($words) === 0) { return true; } $comment_words = explode(' ', $this->content); foreach($words as $word) { if (in_array($word->word, $comment_words)) { return false; } } return true; } }