2020-12-01 17:02:10 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2021-09-08 16:43:44 +02:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
use Kwaadpepper\CrudPolicies\Enums\CrudAction;
|
|
|
|
|
use Kwaadpepper\CrudPolicies\Enums\CrudType;
|
|
|
|
|
use Kwaadpepper\CrudPolicies\Traits\IsCrudModel;
|
2020-12-01 17:02:10 +01:00
|
|
|
|
2020-12-02 10:08:27 +01:00
|
|
|
class SingleOptin extends Model
|
2020-12-01 17:02:10 +01:00
|
|
|
{
|
|
|
|
|
use HasFactory;
|
2021-09-08 16:43:44 +02:00
|
|
|
use IsCrudModel;
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/** @var string */
|
2021-09-08 16:43:44 +02:00
|
|
|
protected $crudLabelColumn = 'email';
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/** @var string */
|
2021-09-08 16:43:44 +02:00
|
|
|
protected $crudValueColumn = 'id';
|
2020-12-01 17:02:10 +01:00
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
|
*
|
|
|
|
|
* @var string[]
|
|
|
|
|
*/
|
2021-03-14 10:45:42 +01:00
|
|
|
protected $fillable = [
|
|
|
|
|
'email'
|
|
|
|
|
];
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* SingleOptin
|
|
|
|
|
*
|
|
|
|
|
* @param array $attributes
|
|
|
|
|
*/
|
2021-09-08 16:43:44 +02:00
|
|
|
public function __construct(array $attributes = [])
|
|
|
|
|
{
|
|
|
|
|
self::$editableProperties = [
|
|
|
|
|
'email' => [
|
|
|
|
|
'label' => Str::ucfirst(trans('models.common.email')),
|
|
|
|
|
'type' => CrudType::email(),
|
|
|
|
|
'validate' => [
|
|
|
|
|
'required',
|
|
|
|
|
'email:rfc,dns',
|
|
|
|
|
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
|
|
|
function ($attribute, $value, $fail) {
|
|
|
|
|
$q = static::query();
|
|
|
|
|
if (request()->user) {
|
|
|
|
|
$q = $q->where('id', '!=', $this->id);
|
|
|
|
|
}
|
|
|
|
|
if ($q->where('email', $value)->exists()) {
|
|
|
|
|
$fail(__(':attribute est déjà utilisé', [
|
|
|
|
|
'attribute' => $attribute
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
'actions' => [
|
|
|
|
|
CrudAction::viewAny(),
|
|
|
|
|
CrudAction::view(),
|
|
|
|
|
CrudAction::create(),
|
|
|
|
|
CrudAction::update()
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'brand_id' => [
|
2021-09-09 15:15:23 +02:00
|
|
|
'label' => Str::ucfirst(trans('models.classes.brand')),
|
2021-09-08 16:43:44 +02:00
|
|
|
'type' => CrudType::belongsTo(),
|
|
|
|
|
'belongsTo' => Brand::class,
|
|
|
|
|
'actions' => [
|
|
|
|
|
CrudAction::viewAny(),
|
|
|
|
|
CrudAction::view()
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'created_at' => [
|
|
|
|
|
'label' => Str::ucfirst(trans('models.common.optinDate')),
|
|
|
|
|
'type' => CrudType::string(),
|
|
|
|
|
'readonly' => true,
|
|
|
|
|
'actions' => [
|
|
|
|
|
CrudAction::viewAny(),
|
|
|
|
|
CrudAction::view(),
|
|
|
|
|
CrudAction::update()
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
parent::__construct($attributes);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
// * RELATIONS
|
|
|
|
|
|
2021-02-28 12:04:49 +01:00
|
|
|
/**
|
|
|
|
|
* Brand BelongsTo relation
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
|
|
|
|
public function brand()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Brand::class);
|
2020-12-01 17:02:10 +01:00
|
|
|
}
|
|
|
|
|
}
|