<?php

namespace App\Models\Graphics;

use Illuminate\Database\Eloquent\Model;

class BackgroundImage extends Model
{
    protected $guarded = [];

    // explicitly define tables
    protected $table = 'user_background_images';

    protected $fillable = [
        'user_id', 'name', 'type','size', 'location', 'path', 'public'
    ];

    public function owner()
    {
        return $this->hasOne('App\Models\Auth\User', 'id', 'user_id');
    }

    public function path()
    {
        return \url('/backgrounds') . '/' . $this->id;
    }

    public function scopePublicBackgrounds($query){
        return $query-> where('public', '=', '1');
        ;
    }
}
