130 lines
2.9 KiB
PHP
130 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Kwaadpepper\CrudPolicies\Enums\CrudAction;
|
|
use Kwaadpepper\CrudPolicies\Enums\CrudType;
|
|
use Kwaadpepper\CrudPolicies\Traits\IsCrudModel;
|
|
|
|
class Log extends Model
|
|
{
|
|
use HasFactory;
|
|
use IsCrudModel;
|
|
|
|
/**
|
|
* Crud label column
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $crudLabelColumn = 'id';
|
|
|
|
/**
|
|
* Crud value column
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $crudValueColumn = 'id';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = ['entry'];
|
|
|
|
/**
|
|
* Log
|
|
*
|
|
* @param array $attributes
|
|
*/
|
|
public function __construct(array $attributes = [])
|
|
{
|
|
self::$editableProperties = [
|
|
'id' => [
|
|
'label' => trans('ID'),
|
|
'type' => CrudType::unsignedint(),
|
|
'actions' => [
|
|
CrudAction::viewAny(),
|
|
CrudAction::view()
|
|
]
|
|
],
|
|
'entry' => [
|
|
'label' => trans('Entrée'),
|
|
'type' => CrudType::text(),
|
|
'required' => true,
|
|
'nullable' => false,
|
|
'actions' => [
|
|
CrudAction::viewAny(),
|
|
CrudAction::view(),
|
|
CrudAction::create(),
|
|
CrudAction::update(),
|
|
]
|
|
],
|
|
'created_at' => [
|
|
'label' => trans('Créé le'),
|
|
'type' => CrudType::string(),
|
|
'actions' => [
|
|
CrudAction::viewAny(),
|
|
CrudAction::view()
|
|
]
|
|
]
|
|
];
|
|
parent::__construct($attributes);
|
|
}
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted()
|
|
{
|
|
static::creating(function (Log $log) {
|
|
$log->user()->associate(auth()->user());
|
|
});
|
|
}
|
|
|
|
// * RELATIONSHIPS
|
|
|
|
/**
|
|
* BelongsTo User relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* MorphTo parent object relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
|
*/
|
|
public function parent()
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
/**
|
|
* MorphTo parent object site relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
|
*/
|
|
public function parentSite()
|
|
{
|
|
return $this->morphTo('parent', 'site');
|
|
}
|
|
|
|
/**
|
|
* MorphTo parent object project relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
|
*/
|
|
public function parentProject()
|
|
{
|
|
return $this->morphTo('parent', 'project');
|
|
}
|
|
}
|