Task.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Builder;
  6. class Task extends Model
  7. {
  8. use HasFactory;
  9. protected $primaryKey = 'id';
  10. protected $casts = [
  11. "date" => "date:Y-m-d",
  12. "time" => "date:H:i",
  13. "duration" => "date:H:i"
  14. ];
  15. protected $fillable = ['name', 'type_id', 'place', 'date', 'time', 'duration', 'comment', 'done', 'user_id'];
  16. protected $visible = ['id', 'name', 'place', 'date', 'time', 'duration', 'comment', 'type', 'done', 'user_id'];
  17. protected $hidden = ["created_at", "updated_at"];
  18. protected $with = ['type'];
  19. public function type() {
  20. return $this->belongsTo('App\Models\TaskType');
  21. }
  22. public function user() {
  23. return $this->belongsTo('App\Models\User');
  24. }
  25. protected static function boot()
  26. {
  27. parent::boot();
  28. // Order by name ASC
  29. static::addGlobalScope('order', function (Builder $builder) {
  30. $builder->orderBy('id', 'asc');
  31. });
  32. }
  33. }