Lae/app/Models/Module/ProviderModule.php

52 lines
1000 B
PHP
Raw Normal View History

2022-08-13 06:04:47 +00:00
<?php
namespace App\Models\Module;
2022-08-13 08:37:17 +00:00
use Illuminate\Support\Str;
use App\Models\Module\Module;
use App\Models\Module\Provider;
2022-08-13 06:04:47 +00:00
use Illuminate\Database\Eloquent\Model;
2022-08-13 08:37:17 +00:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
2022-08-13 06:04:47 +00:00
class ProviderModule extends Model
{
use HasFactory;
protected $table = 'provider_modules';
protected $fillable = [
'provider_id',
'module_id',
'is_enabled',
2022-08-13 08:37:17 +00:00
// 'api_token'
2022-08-13 06:04:47 +00:00
];
public function provider()
{
return $this->belongsTo(Provider::class);
}
public function module()
{
return $this->belongsTo(Module::class);
}
public function getIsEnabledAttribute($value)
{
return (bool) $value;
}
2022-08-13 08:37:17 +00:00
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
// if local
if (!app()->environment('local')) {
$model->api_token = Str::random(60);
}
});
}
2022-08-13 06:04:47 +00:00
}