2022-10-13 11:41:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class SiteUri extends Model
|
|
|
|
{
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
'uri',
|
|
|
|
];
|
|
|
|
|
|
|
|
/* RELATIONS */
|
|
|
|
|
|
|
|
public function site()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Site::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ATTRIBUTES */
|
|
|
|
|
|
|
|
public function getActiveAttribute(bool $value): bool
|
|
|
|
{
|
2022-10-28 13:38:22 +00:00
|
|
|
return ($value && (strlen($this->redirect) > 0)) || $this->site->redirect;
|
2022-10-13 11:41:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getDelayAttribute(int $value=NULL): int
|
|
|
|
{
|
|
|
|
return $this->active && $value ? $value : $this->site->delay;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMessageAttribute(string $value=NULL): string
|
|
|
|
{
|
|
|
|
return $this->active && $value ? $value : $this->site->message;
|
|
|
|
}
|
|
|
|
|
2022-10-28 13:38:22 +00:00
|
|
|
public function getPermanentAttribute(bool $value): bool
|
|
|
|
{
|
|
|
|
return $value || $this->site->permanent;
|
|
|
|
}
|
|
|
|
|
2022-10-13 11:41:38 +00:00
|
|
|
public function getRedirectAttribute(string $value=NULL): string
|
|
|
|
{
|
|
|
|
return ($x=($this->getRawOriginal('active') && $value ? $value : $this->site->redirect)) ? $x.(request()->getRequestUri() != '/' ? request()->getRequestUri() : '') : '';
|
|
|
|
}
|
|
|
|
}
|