You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.6 KiB
65 lines
1.6 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Manager;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class Project extends SoftDeletesModel
|
|
{
|
|
protected $table = "project";
|
|
public $appends = ["logo_url", "banners_url"];
|
|
|
|
public function scopeAdminProject($query)
|
|
{
|
|
$ids = Auth::guard("admin")->user()->project_ids;
|
|
if ($ids) {
|
|
$split = (new CommonModel())->split;
|
|
$ids = explode($split, $ids);
|
|
$query->whereIn('id', $ids);
|
|
}
|
|
}
|
|
|
|
public function getLogoUrlAttribute()
|
|
{
|
|
$protocol = request()->secure() ? "https" : "http";
|
|
return $this->logo ? $protocol . "://" . request()->getHost() . $this->logo : $this->logo;
|
|
}
|
|
|
|
public function getBannersUrlAttribute()
|
|
{
|
|
$protocol = request()->secure() ? "https" : "http";
|
|
return $this->banners ? $protocol . "://" . request()->getHost() . $this->banners : $this->banners;
|
|
}
|
|
|
|
public function buildings()
|
|
{
|
|
return $this->hasMany(Building::class);
|
|
}
|
|
|
|
public function areas()
|
|
{
|
|
return $this->hasMany(Area::class, Building::class);
|
|
}
|
|
|
|
public function paramedicLevels()
|
|
{
|
|
return $this->hasMany(ParamedicLevel::class);
|
|
}
|
|
|
|
public function products()
|
|
{
|
|
return $this->hasMany(Product::class, "project_id", "id");
|
|
}
|
|
|
|
public function defaultProduct()
|
|
{
|
|
return $this->hasOne(Product::class, "project_id", "id");
|
|
}
|
|
|
|
public function managers()
|
|
{
|
|
return $this->hasManyThrough(Manager::class, ManagerProject::class, "project_id", "id", "id", "manager_id");
|
|
}
|
|
}
|