| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 | 
							- <?php
 
- namespace App\Models;
 
- use Illuminate\Database\Eloquent\Model;
 
- use Illuminate\Database\Eloquent\SoftDeletes;
 
- class Article extends Model
 
- {
 
- 	use SoftDeletes;
 
- 	// Приведение к datetime нужно для использования метода isPast
 
- 	protected $casts = [
 
- 		"publish_at" => "datetime",
 
- 		"unpublish_at" => "datetime"
 
- 	];
 
- 	const STATUS_DRAFT		= 0;
 
- 	const STATUS_PENDING	= 1;
 
- 	const STATUS_PUBLISHED	= 2;
 
- 	const STATUS_ARCHIVE	= 3;
 
- 	function scopePending($query) {
 
- 		$query->where("status", static::STATUS_PENDING);
 
- 	}
 
- 	function scopePublished($query) {
 
- 		$query->where("status", static::STATUS_PUBLISHED);
 
- 	}
 
- 	function comments() {
 
- 		return $this->morphMany(Comment::class, "commentable");
 
- 	}
 
- 	function publish() {
 
- 		$this->status = static::STATUS_PUBLISHED;
 
- 		$this->save();
 
- 	}
 
- 	function unpublish() {
 
- 		$this->status = static::STATUS_ARCHIVE;
 
- 		$this->save();
 
- 	}
 
- 	// Для страницы модерации
 
- 	function link() {
 
- 		return "/article/$this->id";
 
- 	}
 
- }
 
 
  |