condorrocks/condor

View on GitHub
app/Board.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

/**
 * @property int $id
 * @property string $name
 * @property string $alert_to
 * @property \Illuminate\Support\Collection $accounts
 * @property \Illuminate\Support\Collection $feeds
 * @property \Illuminate\Support\Collection $snapshots
 */
class Board extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'alert_to'
    ];

    public function accounts()
    {
        return $this->belongsToMany(Account::class);
    }

    public function feeds()
    {
        return $this->belongsToMany(Feed::class)->with('aspect');
    }

    public function snapshots()
    {
        return $this->hasMany(Snapshot::class)->with('aspect');
    }

    public function defaultAccount()
    {
        return $this->accounts()->first();
    }

    /**
     * Set alert_to.
     *
     * @param string $alert_to
     */
    public function setAlertToAttribute($alert_to)
    {
        $this->attributes['alert_to'] = trim($alert_to) ?: null;
    }
}