| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 | 
							- <?php
 
- namespace App\Models;
 
- use Illuminate\Database\Eloquent\Model;
 
- use Illuminate\Database\Eloquent\SoftDeletes;
 
- class Comment extends Model
 
- {
 
- 	use SoftDeletes;
 
- 	const STATUS_PENDING	= 0;
 
- 	const STATUS_PUBLISHED	= 1;
 
- 	const STATUS_REJECTED	= 2;
 
- 	// Наличие fillable требуется только при использовании mass assignment, т.е. создание записи из ассоциативного массива
 
- 	protected $fillable = [
 
- 		"name",
 
- 		"email",
 
- 		"content",
 
- 		"status"
 
- 	];
 
- 	function commentable() {
 
- 		return $this->morphTo();
 
- 	}
 
- 	function scopePending($query) {
 
- 		$query->where("status", static::STATUS_PENDING);
 
- 	}
 
- 	function scopePublished($query) {
 
- 		$query->where("status", static::STATUS_PUBLISHED);
 
- 	}
 
- 	function scopeRecent($query) {
 
- 		$query->orderBy("created_at", "desc");
 
- 	}
 
- 	function allow() {
 
- 		$this->status = static::STATUS_PUBLISHED;
 
- 		$this->save();
 
- 	}
 
- 	function reject() {
 
- 		$this->status = static::STATUS_REJECTED;
 
- 		$this->save();
 
- 	}
 
- }
 
 
  |