<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Directory extends Model
{
    /**
     * [$guarded description]
     * @var array
     */
    protected $guarded = [];

    /**
     * [$hidden description]
     * @var [type]
     */
    protected $hidden = [
        'created_at','updated_at'
    ];

    /**
     * [$appends description]
     * @var [type]
     */
    protected $appends = [
        'size'
    ];

    /**
     * [file description]
     * @return [type] [description]
     */
    public function file()
    {
        return $this->hasMany(File::class);
    }

    /**
     * [getSizeAttribute description]
     * @return [type] [description]
     */
    public function getSizeAttribute()
    {
        return File::where('directory_id', $this->id)->get()->sum('size');
    }
}
