Files
monica/app/Task.php
T
Yamamoto KadirandRégis Freyd 496d23e4a7 Separate PeopleController into smaller chunks (#253)
* Edit relation docblocks of Contact model
* Move activities to its own controller
* Move reminders to its own controller
* Move tasks to its own controller
* Refactor Gift in preparation for the move
* Move gifts into its own controller
* Fix failing tests
* Move debt to its own controllelr
* Fix tests failing on PHP7
* Move significant others to its own controller
* Move kids to its own controller
* Move notes to its own controller
* Some more adjustments & solving #277
And more query optimizations
2017-06-15 15:03:22 -04:00

104 lines
1.9 KiB
PHP

<?php
namespace App;
use Auth;
use App\Helpers\DateHelper;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* @property Account $account
* @property Contact $contact
* @method static Builder completed()
* @method static Builder inProgress()
*/
class Task extends Model
{
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = ['id'];
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['completed_at'];
/**
* Get the account record associated with the task.
*
* @return BelongsTo
*/
public function account()
{
return $this->belongsTo(Account::class);
}
/**
* Get the contact record associated with the task.
*
* @return BelongsTo
*/
public function contact()
{
return $this->belongsTo(Contact::class);
}
/**
* Limit tasks to completed ones
*
* @param Builder $query
* @return Builder
*/
public function scopeCompleted(Builder $query)
{
return $query->where('status', 'completed');
}
/**
* Limit tasks to in-progress ones
*
* @param Builder $query
* @return Builder
*/
public function scopeInProgress(Builder $query)
{
return $query->where('status', 'inprogress');
}
/**
* Toggle task status
*
* @return static
*/
public function toggle()
{
$this->status = $this->status === 'completed' ? 'inprogress' : 'completed';
$this->save();
return $this;
}
public function getTitle()
{
return $this->title;
}
public function getDescription()
{
return $this->description;
}
public function getCreatedAt()
{
return $this->created_at;
}
}