12345678910111213141516171819202122232425262728293031 |
- <?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 scopePublished($query) {
- $query->where("status", static::STATUS_PUBLISHED);
- }
- function scopeRecent($query) {
- $query->orderBy("created_at", "desc");
- }
- }
|