2020-11-18 10:23:51 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2023-08-16 10:23:50 +00:00
|
|
|
use App\Lib\Helpers\ToolboxHelper;
|
2020-11-18 10:23:51 +01:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2023-08-14 17:48:26 +00:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
2025-04-17 16:22:23 +02:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
2023-10-12 16:13:54 +02:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2020-11-18 10:23:51 +01:00
|
|
|
|
2023-08-14 09:23:39 +00:00
|
|
|
/**
|
2023-08-16 08:28:59 +00:00
|
|
|
* @property string $name
|
2023-08-16 10:23:50 +00:00
|
|
|
* @property string $url_re7
|
|
|
|
|
* @property string $url_prod
|
2023-08-16 08:28:59 +00:00
|
|
|
* @property integer $gitlab_project_id
|
|
|
|
|
* @property Brand $brand_id
|
2023-08-14 09:23:39 +00:00
|
|
|
*/
|
2021-07-23 11:34:16 +02:00
|
|
|
class Site extends Model
|
2020-11-18 10:23:51 +01:00
|
|
|
{
|
|
|
|
|
use HasFactory;
|
2023-10-12 16:13:54 +02:00
|
|
|
use SoftDeletes;
|
2021-06-18 15:39:19 +02:00
|
|
|
|
2022-05-24 12:38:30 +02:00
|
|
|
/**
|
2023-08-14 09:23:39 +00:00
|
|
|
* The attributes that are fillable.
|
2022-05-24 12:38:30 +02:00
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2021-07-27 14:50:54 +02:00
|
|
|
protected $fillable = [
|
2023-08-14 09:23:39 +00:00
|
|
|
'name',
|
2023-08-16 10:23:50 +00:00
|
|
|
'url_re7',
|
|
|
|
|
'url_prod',
|
2025-04-17 16:22:23 +02:00
|
|
|
'gitlab_project_id',
|
|
|
|
|
'project_manager_id'
|
2021-07-27 14:50:54 +02:00
|
|
|
];
|
2021-04-18 10:43:36 +02:00
|
|
|
|
2023-08-14 17:48:26 +00:00
|
|
|
/**
|
|
|
|
|
* The accessors to append to the model's array form.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $appends = [
|
|
|
|
|
'value'
|
|
|
|
|
];
|
2023-08-16 10:23:50 +00:00
|
|
|
// * EVENTS
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Perform any actions required after the model boots.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected static function booted()
|
|
|
|
|
{
|
|
|
|
|
static::creating(function (self $model) {
|
|
|
|
|
self::manageFields($model);
|
|
|
|
|
});
|
|
|
|
|
static::updating(function (self $model) {
|
|
|
|
|
self::manageFields($model);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// * METHODS
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Common methods function.
|
|
|
|
|
*
|
|
|
|
|
* @param Model $model
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
private static function manageFields(Model $model)
|
|
|
|
|
{
|
|
|
|
|
if ($model->url_re7) {
|
|
|
|
|
ToolboxHelper::assertNoInternalUrls('url_re7', $model->url_re7);
|
|
|
|
|
}
|
|
|
|
|
if ($model->url_prod) {
|
|
|
|
|
ToolboxHelper::assertNoInternalUrls('url_prod', $model->url_prod);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-14 17:48:26 +00:00
|
|
|
|
2022-05-24 12:38:30 +02:00
|
|
|
// * RELATIONSHIPS
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* HasMany Message relation
|
|
|
|
|
* The users of type client that would have access to this site tickets
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
*/
|
2021-06-18 15:39:19 +02:00
|
|
|
public function users()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(User::class);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-24 12:38:30 +02:00
|
|
|
/**
|
|
|
|
|
* HasMany Ticket relation
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
*/
|
2021-04-18 10:43:36 +02:00
|
|
|
public function tickets()
|
|
|
|
|
{
|
2021-07-23 11:34:16 +02:00
|
|
|
return $this->hasMany(Ticket::class, 'site_id');
|
2020-11-18 10:23:51 +01:00
|
|
|
}
|
2021-04-18 10:43:36 +02:00
|
|
|
|
2022-05-31 14:06:07 +02:00
|
|
|
/**
|
|
|
|
|
* BelongsTo Brand relation
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
|
|
|
|
public function brand()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Brand::class);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-17 16:22:23 +02:00
|
|
|
/**
|
|
|
|
|
* BelongsTo User relation
|
|
|
|
|
* The project manager of the site
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
|
|
|
|
public function projectManager(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class, 'project_manager_id');
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-24 12:38:30 +02:00
|
|
|
/**
|
2022-08-30 06:41:39 +00:00
|
|
|
* BelongsTo Project relation
|
2022-05-24 12:38:30 +02:00
|
|
|
*
|
2022-08-30 06:41:39 +00:00
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2022-05-24 12:38:30 +02:00
|
|
|
*/
|
2022-08-30 06:41:39 +00:00
|
|
|
public function project()
|
2021-07-25 19:11:33 +02:00
|
|
|
{
|
2022-08-30 06:41:39 +00:00
|
|
|
return $this->belongsTo(Project::class);
|
2021-07-25 19:11:33 +02:00
|
|
|
}
|
2023-08-14 17:48:26 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return value attribute for belongsto search component
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Casts\Attribute
|
|
|
|
|
*/
|
|
|
|
|
protected function value(): Attribute
|
|
|
|
|
{
|
|
|
|
|
return new Attribute(
|
|
|
|
|
get: fn () => $this->id,
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-11-18 10:23:51 +01:00
|
|
|
}
|