<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class Banners extends Model {
	protected $table = 'banners';
	protected $fillable = [ 
			'name',
			'image',
			'url',
			'start_at',
			'end_at',
			'status'
	];
	public function getImageUrlAttribute() {
		// 如果 image 字段本身就已经是完整的 url 就直接返回
		if (Str::startsWith ( $this->attributes ['image'], [ 
				'http://',
				'https://'
		] )) {
			return $this->attributes ['image'];
		}
		return \Storage::disk ( 'local' )->url ( $this->attributes ['image'] );
	}
}
