Merge branch 'reclas' into 'develop'
Add claim functionnality Closes #40 See merge request ldc-web/projets/crm!35
This commit is contained in:
commit
515bbf4758
228 changed files with 9410 additions and 2606 deletions
|
|
@ -175,9 +175,9 @@ class UserCreate extends Command
|
|||
[
|
||||
Str::ucFirst(RoleEnum::conceptor->label()),
|
||||
Str::ucFirst(RoleEnum::admin->label()),
|
||||
Str::ucFirst(RoleEnum::visitor->label())
|
||||
Str::ucFirst(RoleEnum::marketing->label())
|
||||
],
|
||||
Str::ucFirst(RoleEnum::visitor->label()),
|
||||
Str::ucFirst(RoleEnum::marketing->label()),
|
||||
);
|
||||
if ($tmp === Str::ucFirst(RoleEnum::conceptor->label())) {
|
||||
$tmp = RoleEnum::conceptor;
|
||||
|
|
@ -185,8 +185,8 @@ class UserCreate extends Command
|
|||
if ($tmp === Str::ucFirst(RoleEnum::admin->label())) {
|
||||
$tmp = RoleEnum::admin;
|
||||
}
|
||||
if ($tmp === Str::ucFirst(RoleEnum::visitor->label())) {
|
||||
$tmp = RoleEnum::visitor;
|
||||
if ($tmp === Str::ucFirst(RoleEnum::marketing->label())) {
|
||||
$tmp = RoleEnum::marketing;
|
||||
}
|
||||
$validator = Validator::make(['role' => $tmp], [
|
||||
'role' => 'required'
|
||||
|
|
|
|||
21
app/Enums/Claims/ClaimMessageType.php
Normal file
21
app/Enums/Claims/ClaimMessageType.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums\Claims;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ClaimMessageType: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case system = 1;
|
||||
case human = 2;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::system->name => 'Système',
|
||||
self::human->name => 'Humain',
|
||||
];
|
||||
}
|
||||
51
app/Enums/Claims/ClaimResponseType.php
Normal file
51
app/Enums/Claims/ClaimResponseType.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums\Claims;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ClaimResponseType: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case none = 1;
|
||||
case manual = 2;
|
||||
case mail = 3;
|
||||
case email = 4;
|
||||
case phone = 5;
|
||||
case other = 99;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::none->name => 'Non défini',
|
||||
self::manual->name => 'Manuelle',
|
||||
self::mail->name => 'Courrier',
|
||||
self::email->name => 'E-mail',
|
||||
self::phone->name => 'Téléphone',
|
||||
self::other->name => 'Autre',
|
||||
];
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*/
|
||||
private const COLORS = [
|
||||
self::none->name => '#b8b8b8',
|
||||
self::manual->name => '#a7a7a7',
|
||||
self::mail->name => '#757575',
|
||||
self::email->name => '#5e5e5e',
|
||||
self::phone->name => '#414141',
|
||||
self::other->name => '#2b2b2b',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get Class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function color(): string
|
||||
{
|
||||
return self::COLORS[$this->name];
|
||||
}
|
||||
}
|
||||
45
app/Enums/Claims/ClaimStatus.php
Normal file
45
app/Enums/Claims/ClaimStatus.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums\Claims;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ClaimStatus: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case untreated = 1;
|
||||
case sentDigital = 2;
|
||||
case sentMarketing = 3;
|
||||
case treated = 4;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::untreated->name => 'Non traitée',
|
||||
self::sentDigital->name => 'Transférée au service Digital',
|
||||
self::sentMarketing->name => 'Retournée au Marketing',
|
||||
self::treated->name => 'Traitée',
|
||||
];
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*/
|
||||
private const COLORS = [
|
||||
self::untreated->name => '#5a5a5a',
|
||||
self::sentDigital->name => '#0033c0',
|
||||
self::sentMarketing->name => '#69077c',
|
||||
self::treated->name => '#188618',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get Class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function color(): string
|
||||
{
|
||||
return self::COLORS[$this->name];
|
||||
}
|
||||
}
|
||||
42
app/Enums/Claims/ClaimType.php
Normal file
42
app/Enums/Claims/ClaimType.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums\Claims;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ClaimType: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case classic = 1;
|
||||
case br = 2;
|
||||
case rgpd = 3;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::classic->name => 'Classique',
|
||||
self::br->name => 'BR',
|
||||
self::rgpd->name => 'RGPD',
|
||||
];
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*/
|
||||
private const COLORS = [
|
||||
self::classic->name => '#08818a',
|
||||
self::br->name => '#9021f8',
|
||||
self::rgpd->name => '#c2237a',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get Class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function color(): string
|
||||
{
|
||||
return self::COLORS[$this->name];
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ enum RoleEnum: int
|
|||
|
||||
case conceptor = 1;
|
||||
case admin = 2;
|
||||
case visitor = 3;
|
||||
case marketing = 3;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
|
|
@ -18,6 +18,6 @@ enum RoleEnum: int
|
|||
private const LABELS = [
|
||||
self::conceptor->name => 'Concepteur',
|
||||
self::admin->name => 'Administrateur',
|
||||
self::visitor->name => 'Visiteur',
|
||||
self::marketing->name => 'Marketing',
|
||||
];
|
||||
}
|
||||
|
|
|
|||
55
app/Events/ClaimModelChanged.php
Normal file
55
app/Events/ClaimModelChanged.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Claim;
|
||||
use App\Models\User;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ClaimModelChanged
|
||||
{
|
||||
use Dispatchable;
|
||||
use InteractsWithSockets;
|
||||
use SerializesModels;
|
||||
|
||||
/** @var \App\Models\Claim $claim Current claim modified. */
|
||||
public $claim;
|
||||
|
||||
/** @var string $field Modified field. */
|
||||
public $field;
|
||||
|
||||
/** @var string $label Label of the modified field. */
|
||||
public $label;
|
||||
|
||||
/** @var \App\Models\User|null $user Current authenticated user. */
|
||||
public $user;
|
||||
|
||||
/** @var string|null $content Custom content message. */
|
||||
public $content;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param \App\Models\Claim $claim
|
||||
* @param string $field
|
||||
* @param string $label
|
||||
* @param \App\Models\User|null $user
|
||||
* @param string|null $content
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
Claim $claim,
|
||||
string $field,
|
||||
string $label,
|
||||
User|null $user = null,
|
||||
string|null $content = null,
|
||||
) {
|
||||
$this->claim = $claim;
|
||||
$this->field = $field;
|
||||
$this->label = $label;
|
||||
$this->user = $user;
|
||||
$this->content = $content;
|
||||
}
|
||||
}
|
||||
31
app/Http/Controllers/Api/V4/ClaimController.php
Normal file
31
app/Http/Controllers/Api/V4/ClaimController.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V4;
|
||||
|
||||
use App\Exceptions\Api\V4\CrmException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Api\V4\SendClaimRequest;
|
||||
use App\Models\Claim;
|
||||
use App\Models\Service;
|
||||
|
||||
class ClaimController extends Controller
|
||||
{
|
||||
/**
|
||||
* Just returns HTTP 200 response.
|
||||
*
|
||||
* @param \App\Http\Requests\Api\V4\SendClaimRequest $request
|
||||
* @param \App\Models\Service $service
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws \App\Exceptions\Api\V4\CrmException If the single optin could not be added or removed.
|
||||
*/
|
||||
public function store(SendClaimRequest $request, Service $service): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$claimModel = (new Claim())->fill($request->validated());
|
||||
if (!$claimModel->saveOrFail()) {
|
||||
throw new CrmException('Api failed to store claim.');
|
||||
}
|
||||
$claimModel->brand()->associate($service->brand);
|
||||
|
||||
return response()->json();
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,14 @@ class ActivityLogsController extends Controller
|
|||
use ChangesModelOrder;
|
||||
use UpdateModelPublished;
|
||||
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(ActivityLog::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -13,6 +13,14 @@ use Illuminate\Support\Str;
|
|||
|
||||
class AnswerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(Answer::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -5,14 +5,24 @@ namespace App\Http\Controllers\Bo;
|
|||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Brands\StoreBrandRequest;
|
||||
use App\Http\Requests\Bo\Brands\UpdateBrandRequest;
|
||||
use App\Http\Requests\Bo\PaginateModelsRequest;
|
||||
use App\Models\Brand;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Uwil\LaravelCommon\Helpers\CollectionHelper;
|
||||
|
||||
class BrandController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(Brand::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
|
|
@ -128,16 +138,18 @@ class BrandController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* Get a paginate resource.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\PaginateModelsRequest $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function jsonPaginate(): \Illuminate\Http\JsonResponse
|
||||
public function jsonPaginateModels(PaginateModelsRequest $request): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
return DB::transaction(function () {
|
||||
/** @var \App\Models\Brand */
|
||||
$brandModels = Brand::paginate(12);
|
||||
return \response()->json($brandModels ?? 500);
|
||||
});
|
||||
$models = CollectionHelper::paginateManually(
|
||||
Brand::getUserAssociatedBrands(),
|
||||
$this->jsonItemPerPagination,
|
||||
(int)$request->validated('page'),
|
||||
);
|
||||
return \response()->json($models);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
204
app/Http/Controllers/Bo/ClaimController.php
Normal file
204
app/Http/Controllers/Bo/ClaimController.php
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Enums\Claims\ClaimResponseType;
|
||||
use App\Enums\Claims\ClaimStatus;
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Events\ClaimModelChanged;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Claims\SendClaimAnswerRequest;
|
||||
use App\Http\Requests\Bo\Claims\UpdateClaimRequest;
|
||||
use App\Http\Requests\Bo\PaginateModelsRequest;
|
||||
use App\Mail\ClaimAnswerMail;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Claim;
|
||||
use App\Models\ClaimMailTemplate;
|
||||
use App\Models\ClaimMessage;
|
||||
use App\Models\ClaimSubject;
|
||||
use App\Traits\Controllers\UpdateModelPublished;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Uwil\LaravelCommon\Helpers\CollectionHelper;
|
||||
|
||||
class ClaimController extends Controller
|
||||
{
|
||||
use UpdateModelPublished;
|
||||
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(Claim::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \App\Models\User $userModel */
|
||||
$userModel = auth('backend')->user();
|
||||
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $claimModels */
|
||||
$claimModels = Claim::query()
|
||||
->when(
|
||||
$request->filled('brand'),
|
||||
fn($q) => $q->whereHas('brand', fn($q) => $q->where('id', $request->brand))
|
||||
)->when(
|
||||
$userModel->role->equals(RoleEnum::marketing),
|
||||
fn($q) => $q->whereHas('brand', fn($q) => $q->whereIn('id', $userModel->brands->modelKeys()))
|
||||
);
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$claimModels,
|
||||
$search,
|
||||
null,
|
||||
'reference',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'email',
|
||||
);
|
||||
}
|
||||
$searchFields = \implode(', ', [
|
||||
trans('validation.custom.reference'),
|
||||
trans('validation.attributes.first_name'),
|
||||
trans('validation.attributes.last_name'),
|
||||
trans('validation.attributes.email'),
|
||||
]);
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($claimModels);
|
||||
|
||||
/** Custom pagination */
|
||||
$claimModels = $this->paginate($claimModels);
|
||||
|
||||
return view('bo.pages.claims.index', compact('claimModels', 'search', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param App\Models\Claim $claim
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(Claim $claim): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$customerClaimModels = !is_null($claim->customer) ? $this->paginate(Claim::query()
|
||||
->whereNotNull('customer_id')
|
||||
->whereHas('brand', fn($q) => $q->whereKey($claim->brand->getKey()))
|
||||
->whereHas('customer', fn($q) => $q->whereKey($claim->customer->getKey()))
|
||||
->whereNot('id', $claim->getKey())
|
||||
->whereNot('status', ClaimStatus::treated)) : collect();
|
||||
$brandModels = CollectionHelper::paginate(
|
||||
Brand::getUserAssociatedBrands(),
|
||||
$this->jsonItemPerPagination,
|
||||
);
|
||||
$claimMessageModels = ClaimMessage::getAllModelsFromClaim($claim->getKey());
|
||||
$claimSubjectModels = CollectionHelper::paginate(
|
||||
ClaimSubject::getAllModelsFromBrand($claim->brand->getKey()),
|
||||
$this->jsonItemPerPagination,
|
||||
);
|
||||
$claimTemplateModels = CollectionHelper::paginate(
|
||||
ClaimMailTemplate::getAllModelsFromBrand($claim->brand->getKey()),
|
||||
$this->jsonItemPerPagination,
|
||||
);
|
||||
|
||||
return view('bo.pages.claims.edit', [
|
||||
'claimModel' => $claim->load(['brand', 'claimSubject']),
|
||||
'customerClaimModels' => $customerClaimModels,
|
||||
'brandModels' => $brandModels,
|
||||
'claimMessageModels' => $claimMessageModels,
|
||||
'claimSubjectModels' => $claimSubjectModels,
|
||||
'claimTemplateModels' => $claimTemplateModels,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Claims\UpdateClaimRequest $request
|
||||
* @param \App\Models\Claim $claim
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update(UpdateClaimRequest $request, Claim $claim): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $claim) {
|
||||
$claim->fill($request->validated());
|
||||
|
||||
if ($claim->saveOrFail()) {
|
||||
$claimMessageModels = ClaimMessage::getAllModelsFromClaim($claim->getKey());
|
||||
return response()->json($claimMessageModels);
|
||||
}
|
||||
return response()->json([], 500);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the claim answer.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Claims\SendClaimAnswerRequest $request
|
||||
* @param \App\Models\Claim $claim
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function answer(SendClaimAnswerRequest $request, Claim $claim): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $claim) {
|
||||
/** @var \App\Models\User $userModel */
|
||||
$userModel = auth()->user();
|
||||
$enum = ClaimResponseType::manual;
|
||||
$claim->response_type = $enum;
|
||||
$claim->status = ClaimStatus::treated;
|
||||
|
||||
if ($claim->saveOrFail()) {
|
||||
// Send the response to the claim author.
|
||||
Mail::to($claim->email)->send(new ClaimAnswerMail($claim, $request->validated()['content']));
|
||||
|
||||
// Create custom event with content message.
|
||||
// @phpcs:disable Generic.Files.LineLength.TooLong
|
||||
$content = sprintf(
|
||||
"<b>%s %s</b> %s <i class='badge' style='background-color:{$enum->color()}'>%s</i><hr class='my-2'>%s",
|
||||
$userModel->first_name,
|
||||
$userModel->last_name,
|
||||
trans('a modifié le :field en', ['field' => trans('validation.custom.response_type')]),
|
||||
$claim->response_type->label(),
|
||||
clean($request->validated()['content']),
|
||||
);
|
||||
event(new ClaimModelChanged($claim, '', '', null, $content));
|
||||
// @phpcs:enable
|
||||
|
||||
// Return conversation.
|
||||
$claimMessageModels = ClaimMessage::getAllModelsFromClaim($claim->getKey());
|
||||
return response()->json($claimMessageModels);
|
||||
} //end if
|
||||
return response()->json([], 500);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a paginate resource.
|
||||
* Needed to overheight the controller method and add a brand condition.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\PaginateModelsRequest $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function jsonClaimPaginateModels(PaginateModelsRequest $request): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$data = $request->validated();
|
||||
$brandModelKey = $request->route()->parameter('brand')->getKey();
|
||||
$models = CollectionHelper::paginateManually(
|
||||
$data['targetModel']::getAllModelsFromBrand($brandModelKey),
|
||||
$this->jsonItemPerPagination,
|
||||
$request->validated('page'),
|
||||
);
|
||||
return \response()->json($models);
|
||||
}
|
||||
}
|
||||
183
app/Http/Controllers/Bo/ClaimMailTemplateController.php
Normal file
183
app/Http/Controllers/Bo/ClaimMailTemplateController.php
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\ClaimMailTemplates\ClaimMailTemplateRequest;
|
||||
use App\Models\Brand;
|
||||
use App\Models\ClaimMailTemplate;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Uwil\LaravelCommon\Helpers\CollectionHelper;
|
||||
|
||||
class ClaimMailTemplateController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(ClaimMailTemplate::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \App\Models\User $userModel */
|
||||
$userModel = auth('backend')->user();
|
||||
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $query */
|
||||
$query = ClaimMailTemplate::query()
|
||||
->when(
|
||||
$request->filled('brand'),
|
||||
fn($q) => $q->whereHas('brand', fn($q) => $q->where('id', $request->brand))
|
||||
)->when(
|
||||
$userModel->role->equals(RoleEnum::marketing),
|
||||
fn($q) => $q->whereHas('brand', fn($q) => $q->whereIn('id', $userModel->brands->modelKeys()))
|
||||
);
|
||||
|
||||
if ($request->search) {
|
||||
$this->searchQuery(
|
||||
$query,
|
||||
$request->search,
|
||||
null,
|
||||
'label',
|
||||
);
|
||||
}
|
||||
|
||||
$this->sortQuery($query);
|
||||
$searchFields = trans('validation.custom.label');
|
||||
|
||||
$claimMailTemplateModels = $this->paginate($query);
|
||||
|
||||
return view('bo.pages.claim_mail_templates.index', compact('claimMailTemplateModels', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*
|
||||
* @param \App\Models\ClaimMailTemplate $claim_mail_template
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show(ClaimMailTemplate $claim_mail_template): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.claim_mail_templates.show', [
|
||||
'claimMailTemplateModel' => $claim_mail_template,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\ClaimMailTemplate $claim_mail_template
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create(ClaimMailTemplate $claim_mail_template): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$brandModels = CollectionHelper::paginate(Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination);
|
||||
return view('bo.pages.claim_mail_templates.create', [
|
||||
'claimMailTemplateModel' => $claim_mail_template,
|
||||
'brandModels' => $brandModels,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\ClaimMailTemplates\ClaimMailTemplateRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(ClaimMailTemplateRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$claimMailTemplateModel = new ClaimMailTemplate();
|
||||
$claimMailTemplateModel->fill($request->validated());
|
||||
if ($claimMailTemplateModel->saveOrFail()) {
|
||||
return redirect()
|
||||
->route('bo.claim_mail_templates.edit', $claimMailTemplateModel)
|
||||
->with('success', trans(
|
||||
':model a été créé.',
|
||||
['model' => Str::singular(trans('models.classes.claimmailtemplates'))]
|
||||
));
|
||||
}
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans(
|
||||
':model n\'a pas été créé.',
|
||||
['model' => Str::singular(trans('models.classes.claimmailtemplates'))]
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\ClaimMailTemplate $claim_mail_template
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(ClaimMailTemplate $claim_mail_template): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$brandModels = CollectionHelper::paginate(Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination);
|
||||
return view('bo.pages.claim_mail_templates.edit', [
|
||||
'claimMailTemplateModel' => $claim_mail_template,
|
||||
'brandModels' => $brandModels,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a spacific resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\ClaimSubjects\ClaimMailTemplateRequest $request
|
||||
* @param \App\Models\ClaimMailTemplate $claim_mail_template
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(
|
||||
ClaimMailTemplateRequest $request,
|
||||
ClaimMailTemplate $claim_mail_template
|
||||
): \Illuminate\Http\RedirectResponse {
|
||||
return DB::transaction(function () use ($request, $claim_mail_template) {
|
||||
$claim_mail_template->fill($request->validated());
|
||||
if ($claim_mail_template->saveOrFail()) {
|
||||
return redirect()
|
||||
->route('bo.claim_mail_templates.edit', $claim_mail_template)
|
||||
->with('success', trans(
|
||||
':model a été mis à jour.',
|
||||
['model' => Str::singular(trans('models.classes.claimmailtemplates'))]
|
||||
));
|
||||
}
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans(
|
||||
':model n\'a pas été mis à jour.',
|
||||
['model' => Str::singular(trans('models.classes.claimmailtemplates'))]
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\ClaimMailTemplate $claim_mail_template
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(ClaimMailTemplate $claim_mail_template): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
if ($claim_mail_template->deleteOrFail()) {
|
||||
return redirect()->route('bo.claim_mail_templates.index')
|
||||
->with('success', __('crud.messages.has_been_deleted', [
|
||||
'model' => Str::of(__('models.classes.claimmailtemplates'))->singular()
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::of(__('models.classes.claimmailtemplates'))->singular()
|
||||
]));
|
||||
}
|
||||
}
|
||||
54
app/Http/Controllers/Bo/ClaimMessageController.php
Normal file
54
app/Http/Controllers/Bo/ClaimMessageController.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\ClaimMessages\StoreMessageRequest;
|
||||
use App\Http\Requests\Bo\ClaimMessages\UpdateMessageRequest;
|
||||
use App\Models\ClaimMessage;
|
||||
use App\Traits\Controllers\UpdateModelPublished;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ClaimMessageController extends Controller
|
||||
{
|
||||
use UpdateModelPublished;
|
||||
|
||||
/**
|
||||
* Store a new specific resource.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\ClaimMessages\StoreMessageRequest $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function store(StoreMessageRequest $request): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$this->authorize('store', ClaimMessage::class);
|
||||
|
||||
return DB::transaction(function () use ($request) {
|
||||
$claimMessage = new ClaimMessage();
|
||||
$claimMessage->fill($request->validated());
|
||||
if ($claimMessage->saveOrFail()) {
|
||||
$claimMessageModels = ClaimMessage::getAllModelsFromClaim($claimMessage->claim->getKey());
|
||||
return response()->json($claimMessageModels);
|
||||
}
|
||||
return response()->json([], 500);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specified resource.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\ClaimMessages\UpdateMessageRequest $request
|
||||
* @param \App\Models\ClaimMessage $claim_message
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update(UpdateMessageRequest $request, ClaimMessage $claim_message): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$this->authorize('update', ClaimMessage::class);
|
||||
|
||||
$model = ClaimMessage::findOrFail($claim_message->getKey());
|
||||
$model->content = $request->validated()['content'];
|
||||
$model->saveOrFail();
|
||||
|
||||
return response()->json();
|
||||
}
|
||||
}
|
||||
173
app/Http/Controllers/Bo/ClaimSubjectController.php
Normal file
173
app/Http/Controllers/Bo/ClaimSubjectController.php
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\ClaimSubjects\ClaimSubjectRequest;
|
||||
use App\Models\Brand;
|
||||
use App\Models\ClaimSubject;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Uwil\LaravelCommon\Helpers\CollectionHelper;
|
||||
|
||||
class ClaimSubjectController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(ClaimSubject::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $query */
|
||||
$query = ClaimSubject::query()->when(
|
||||
$request->filled('brand'),
|
||||
fn($q) => $q->whereHas('brand', fn($q) => $q->where('id', $request->brand))
|
||||
);
|
||||
|
||||
if ($request->search) {
|
||||
$this->searchQuery(
|
||||
$query,
|
||||
$request->search,
|
||||
null,
|
||||
'label',
|
||||
);
|
||||
}
|
||||
|
||||
$this->sortQuery($query);
|
||||
$searchFields = trans('validation.custom.label');
|
||||
|
||||
$claimSubjectModels = $this->paginate($query);
|
||||
|
||||
return view('bo.pages.claim_subjects.index', compact('claimSubjectModels', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*
|
||||
* @param \App\Models\ClaimSubject $claim_subject
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show(ClaimSubject $claim_subject): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.claim_subjects.show', [
|
||||
'claimSubjectModel' => $claim_subject
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\ClaimSubject $claim_subject
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create(ClaimSubject $claim_subject): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$brandModels = CollectionHelper::paginate(Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination);
|
||||
return view('bo.pages.claim_subjects.create', [
|
||||
'claimSubjectModel' => $claim_subject,
|
||||
'brandModels' => $brandModels,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\ClaimSubjects\ClaimSubjectRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(ClaimSubjectRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$claimSubjectModel = new ClaimSubject();
|
||||
$claimSubjectModel->fill($request->validated());
|
||||
if ($claimSubjectModel->saveOrFail()) {
|
||||
return redirect()
|
||||
->route('bo.claim_subjects.edit', $claimSubjectModel)
|
||||
->with('success', trans(
|
||||
':model a été créé.',
|
||||
['model' => Str::singular(trans('models.classes.claimsubjects'))]
|
||||
));
|
||||
}
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans(
|
||||
':model n\'a pas été créé.',
|
||||
['model' => Str::singular(trans('models.classes.claimsubjects'))]
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\ClaimSubject $claim_subject
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(ClaimSubject $claim_subject): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$brandModels = CollectionHelper::paginate(Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination);
|
||||
return view('bo.pages.claim_subjects.edit', [
|
||||
'claimSubjectModel' => $claim_subject,
|
||||
'brandModels' => $brandModels,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a spacific resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\ClaimSubjects\ClaimSubjectRequest $request
|
||||
* @param \App\Models\ClaimSubject $claim_subject
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(ClaimSubjectRequest $request, ClaimSubject $claim_subject): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $claim_subject) {
|
||||
$claim_subject->fill($request->validated());
|
||||
if ($claim_subject->saveOrFail()) {
|
||||
return redirect()
|
||||
->route('bo.claim_subjects.edit', $claim_subject)
|
||||
->with('success', trans(
|
||||
':model a été mis à jour.',
|
||||
['model' => Str::singular(trans('models.classes.claimsubjects'))]
|
||||
));
|
||||
}
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans(
|
||||
':model n\'a pas été mis à jour.',
|
||||
['model' => Str::singular(trans('models.classes.claimsubjects'))]
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\ClaimSubject $claim_subject
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(ClaimSubject $claim_subject): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
if ($claim_subject->deleteOrFail()) {
|
||||
return redirect()->route('bo.claim_subjects.index')
|
||||
->with('success', __('crud.messages.has_been_deleted', [
|
||||
'model' => Str::of(__('models.classes.claimsubjects'))->singular()
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::of(__('models.classes.claimsubjects'))->singular()
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,14 @@ use Symfony\Component\HttpFoundation\StreamedResponse;
|
|||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(Customer::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* View all customers.
|
||||
*
|
||||
|
|
@ -195,6 +203,7 @@ class CustomerController extends Controller
|
|||
*/
|
||||
public function export(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$this->authorize('export', Customer::class);
|
||||
$brands = Brand::all();
|
||||
return view('bo.pages.customers.export', compact(
|
||||
'brands'
|
||||
|
|
|
|||
|
|
@ -3,16 +3,15 @@
|
|||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
/**
|
||||
* Dashboard Page
|
||||
* Dashboard page.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(): View
|
||||
public function index(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.dashboard');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,14 @@ use Symfony\Component\HttpFoundation\StreamedResponse;
|
|||
|
||||
class QuestionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(Question::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
|
|
@ -27,11 +35,11 @@ class QuestionController extends Controller
|
|||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $query */
|
||||
$query = Question::query();
|
||||
$query = Question::query()->when(
|
||||
$request->filled('brand'),
|
||||
fn($q) => $q->whereHas('brand', fn($q) => $q->where('id', $request->brand))
|
||||
);
|
||||
|
||||
if ($request->brand) {
|
||||
$query = $query->where('brand_id', '=', $request->brand);
|
||||
}
|
||||
if ($request->search) {
|
||||
$this->searchQuery(
|
||||
$query,
|
||||
|
|
@ -60,11 +68,10 @@ class QuestionController extends Controller
|
|||
*/
|
||||
public function create(Question $question): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$brandModels = Brand::all();
|
||||
|
||||
$brandModels = Brand::query()->orderBy('name', 'ASC')->paginate($this->jsonItemPerPagination);
|
||||
return view('bo.pages.questions.create', [
|
||||
'questionModel' => $question,
|
||||
'brandModels' => $brandModels
|
||||
'brandModels' => $brandModels
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -104,9 +111,8 @@ class QuestionController extends Controller
|
|||
*/
|
||||
public function edit(Question $question): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$brandModels = Brand::all();
|
||||
$brandModels = Brand::query()->orderBy('name', 'ASC')->paginate($this->jsonItemPerPagination);
|
||||
$question->load('brand');
|
||||
|
||||
return view('bo.pages.questions.edit', [
|
||||
'questionModel' => $question,
|
||||
'brandModels' => $brandModels
|
||||
|
|
@ -183,6 +189,7 @@ class QuestionController extends Controller
|
|||
*/
|
||||
public function export(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$this->authorize('export', Question::class);
|
||||
$brands = Brand::all();
|
||||
return view('bo.pages.questions.export', compact('brands'));
|
||||
}
|
||||
|
|
@ -205,7 +212,7 @@ class QuestionController extends Controller
|
|||
->selectRaw('count(*) as total, answer_id')
|
||||
->from('model_answer')
|
||||
->where('model_type', '=', Customer::class)
|
||||
->whereIn('answer_id', $question->answers->pluck('id'))
|
||||
->whereIn('answer_id', $question->answers->modelKeys())
|
||||
->groupBy('answer_id')
|
||||
->get()
|
||||
->keyBy('answer_id');
|
||||
|
|
|
|||
|
|
@ -14,9 +14,18 @@ use Illuminate\Support\Facades\DB;
|
|||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Str;
|
||||
use Uwil\LaravelCommon\Helpers\CollectionHelper;
|
||||
|
||||
class ServiceController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(Service::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
|
|
@ -26,11 +35,11 @@ class ServiceController extends Controller
|
|||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $query */
|
||||
$query = Service::query();
|
||||
$query = Service::query()->when(
|
||||
$request->filled('brand'),
|
||||
fn($q) => $q->whereHas('brand', fn($q) => $q->where('id', $request->brand))
|
||||
);
|
||||
|
||||
if ($request->brand) {
|
||||
$query = $query->where('brand_id', '=', $request->brand);
|
||||
}
|
||||
if ($request->search) {
|
||||
$this->searchQuery(
|
||||
$query,
|
||||
|
|
@ -58,8 +67,7 @@ class ServiceController extends Controller
|
|||
*/
|
||||
public function create(Service $service): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$brandModels = Brand::all();
|
||||
|
||||
$brandModels = CollectionHelper::paginate(Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination);
|
||||
return view('bo.pages.services.create', [
|
||||
'serviceModel' => $service,
|
||||
'brandModels' => $brandModels
|
||||
|
|
@ -104,8 +112,7 @@ class ServiceController extends Controller
|
|||
*/
|
||||
public function edit(Service $service): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$brandModels = Brand::all();
|
||||
|
||||
$brandModels = CollectionHelper::paginate(Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination);
|
||||
return view('bo.pages.services.edit', [
|
||||
'serviceModel' => $service,
|
||||
'brandModels' => $brandModels
|
||||
|
|
|
|||
|
|
@ -11,6 +11,14 @@ use Illuminate\Support\Str;
|
|||
|
||||
class SingleOptinController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(SingleOptin::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
|
|
@ -46,10 +54,10 @@ class SingleOptinController extends Controller
|
|||
$searchFields = trans('E-mail');
|
||||
|
||||
if ($request->filled('brand')) {
|
||||
$questionModels = Question::where('brand_id', $request->brand)->get();
|
||||
$questionModels = Question::getAllModelsFromBrand($request->brand);
|
||||
|
||||
if ($request->filled('question')) {
|
||||
$answerModels = Answer::where('question_id', $request->question)->get();
|
||||
$answerModels = Answer::getAllModelsFromQuestion($request->question);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,11 @@ use App\Http\Requests\Bo\StatsByBrandRequest;
|
|||
use App\Http\Requests\Bo\StatsByQuestionRequest;
|
||||
use App\Models\Brand;
|
||||
use App\Models\BrandStat;
|
||||
use App\Models\CustomerAnswer;
|
||||
use App\Models\ModelAnswer;
|
||||
use App\Models\Question;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use League\Csv\Writer;
|
||||
|
||||
|
|
@ -24,6 +25,7 @@ class StatsController extends Controller
|
|||
*/
|
||||
public function viewStatsByBrand(StatsByBrandRequest $request)
|
||||
{
|
||||
Gate::authorize('viewStatsByBrand');
|
||||
$stats = null;
|
||||
if ($request->post()) {
|
||||
$stats = BrandStat::query()->whereDate('created_at', '>=', $request->start)
|
||||
|
|
@ -85,6 +87,7 @@ class StatsController extends Controller
|
|||
*/
|
||||
public function viewByQuestion(StatsByQuestionRequest $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
Gate::authorize('viewByQuestion');
|
||||
$question = null;
|
||||
$answers = null;
|
||||
$answersByDays = null;
|
||||
|
|
@ -152,10 +155,12 @@ class StatsController extends Controller
|
|||
*/
|
||||
private function answersByDays(Collection $answers, Carbon $start, Carbon $end): \Illuminate\Support\Collection
|
||||
{
|
||||
Gate::authorize('answersByDays');
|
||||
// * Totalize by date all answers.
|
||||
$answersByDays = CustomerAnswer::query()->whereDate('created_at', '>=', $start)
|
||||
$answersByDays = ModelAnswer::query()
|
||||
->whereDate('created_at', '>=', $start)
|
||||
->whereDate('created_at', '<=', $end)
|
||||
->whereIn('answer_id', $answers->pluck('id'))
|
||||
->whereIn('answer_id', $answers->modelKeys())
|
||||
->get()->map(function ($custAnswer) {
|
||||
return [
|
||||
'answer_id' => $custAnswer->answer_id,
|
||||
|
|
|
|||
|
|
@ -5,13 +5,15 @@ namespace App\Http\Controllers\Bo;
|
|||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Users\StoreUserRequest;
|
||||
use App\Http\Requests\Bo\Users\UpdateUserRequest;
|
||||
use App\Models\Brand;
|
||||
use App\Models\User;
|
||||
use App\Traits\Controllers\UpdateModelPublished;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Uwil\LaravelCommon\Helpers\CollectionHelper;
|
||||
|
||||
class UsersController extends Controller
|
||||
class UserController extends Controller
|
||||
{
|
||||
use UpdateModelPublished;
|
||||
|
||||
|
|
@ -72,7 +74,8 @@ class UsersController extends Controller
|
|||
*/
|
||||
public function create(User $user): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.users.create', ['userModel' => $user]);
|
||||
$brandModels = CollectionHelper::paginate(Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination);
|
||||
return view('bo.pages.users.create', ['userModel' => $user, 'brandModels' => $brandModels]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -88,6 +91,7 @@ class UsersController extends Controller
|
|||
$user->fill($request->validated());
|
||||
|
||||
if ($user->saveOrFail()) {
|
||||
$user->brands()->sync(collect($request->validated()['brand_id'])->pluck('id')->toArray());
|
||||
return redirect()->route('bo.users.edit', $user)
|
||||
->with('success', __('crud.messages.has_been_created', [
|
||||
'model' => Str::ucfirst(__('models.classes.user'))
|
||||
|
|
@ -108,7 +112,8 @@ class UsersController extends Controller
|
|||
*/
|
||||
public function edit(User $user): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.users.edit', ['userModel' => $user]);
|
||||
$brandModels = CollectionHelper::paginate(Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination);
|
||||
return view('bo.pages.users.edit', ['userModel' => $user, 'brandModels' => $brandModels]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -124,6 +129,7 @@ class UsersController extends Controller
|
|||
$user->fill($request->validated());
|
||||
|
||||
if ($user->saveOrFail()) {
|
||||
$user->brands()->sync(collect($request->validated()['brand_id'])->pluck('id')->toArray());
|
||||
return redirect()->route('bo.users.edit', $user)
|
||||
->with('success', __('crud.messages.has_been_updated', [
|
||||
'model' => Str::ucfirst(__('models.classes.user'))
|
||||
|
|
@ -4,11 +4,12 @@ namespace App\Http\Controllers;
|
|||
|
||||
use App\Enums\Pagination\ItemsPerPaginationEnum;
|
||||
use App\Enums\Theme\BootstrapThemeEnum;
|
||||
use App\Http\Requests\Bo\PaginateModelsRequest;
|
||||
use App\Http\Requests\Bo\ThemeRequest;
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
|
@ -20,6 +21,9 @@ class Controller extends BaseController
|
|||
use AuthorizesRequests;
|
||||
use ValidatesRequests;
|
||||
|
||||
/** @var integer $itemPerPagination */
|
||||
public $jsonItemPerPagination = 5;
|
||||
|
||||
/**
|
||||
* Build Search query on specified fields
|
||||
* splitting search into words or using whole sentence
|
||||
|
|
@ -210,16 +214,32 @@ class Controller extends BaseController
|
|||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a paginate resource.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\PaginateModelsRequest $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function jsonPaginateModels(PaginateModelsRequest $request): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Model $models */
|
||||
$models = $request->targetModel::query()
|
||||
->where($request->input('fieldName') ?? 'name', 'like', "%{$request->input('search')}%")
|
||||
->orderBy($request->input('fieldName') ?? 'name', 'ASC')
|
||||
->paginate($request->input('paginate') ?? 10);
|
||||
return \response()->json($models);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bootstrap theme or light (default).
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Http\Requests\Bo\ThemeRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
protected function setTheme(Request $request): \Illuminate\Http\RedirectResponse
|
||||
protected function setTheme(ThemeRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
$theme = ToolboxHelper::getValidatedEnum(
|
||||
$request->theme ?: Cache::get('theme', BootstrapThemeEnum::light->value()),
|
||||
$request->validated('theme') ?: Cache::get('theme', BootstrapThemeEnum::light->value()),
|
||||
'theme',
|
||||
'\App\Http\Controllers\BootstrapThemeEnum',
|
||||
);
|
||||
|
|
|
|||
63
app/Http/Requests/Api/V4/SendClaimRequest.php
Normal file
63
app/Http/Requests/Api/V4/SendClaimRequest.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api\V4;
|
||||
|
||||
use App\Enums\Country;
|
||||
use App\Http\Sanitizers\RemoveSpaces;
|
||||
use ArondeParon\RequestSanitizer\Sanitizers\Capitalize;
|
||||
use ArondeParon\RequestSanitizer\Sanitizers\Lowercase;
|
||||
use ArondeParon\RequestSanitizer\Sanitizers\Trim;
|
||||
use ArondeParon\RequestSanitizer\Sanitizers\TrimDuplicateSpaces;
|
||||
|
||||
class SendClaimRequest extends BaseApiRequest
|
||||
{
|
||||
/**
|
||||
* Using these sanitizers before proceeding the request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $sanitizers = [
|
||||
'first_name' => [Trim::class, TrimDuplicateSpaces::class, Capitalize::class],
|
||||
'last_name' => [Trim::class, TrimDuplicateSpaces::class, Capitalize::class],
|
||||
'email' => [Trim::class, RemoveSpaces::class, Lowercase::class],
|
||||
'address' => [Trim::class, TrimDuplicateSpaces::class],
|
||||
'city' => [Trim::class, TrimDuplicateSpaces::class],
|
||||
'postcode' => [Trim::class],
|
||||
'file' => [Trim::class],
|
||||
'message' => [Trim::class],
|
||||
];
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$countryList = ($this->currentCountry && $this->currentCountry->get('iso')) ?
|
||||
$this->currentCountry->get('iso') : implode(',', Country::getValidIsoAplha2Codes());
|
||||
return [
|
||||
'first_name' => 'required|string|between:3,255',
|
||||
'last_name' => 'required|string|between:3,255',
|
||||
'email' => 'required|email:rfc,dns,spoof,filter|max:255',
|
||||
'address' => 'sometimes|nullable|string|max:255',
|
||||
'city' => 'sometimes|nullable|string|between:2,255',
|
||||
'postcode' => ['sometimes', 'nullable', 'string', "postal_code:{$countryList}"],
|
||||
'file' => 'sometimes|nullable|mimes:jpg,jpeg,png,pdf|max:5120',
|
||||
'message' => 'required|string|min:3',
|
||||
'brand_id' => 'required|integer|exists:brands,id',
|
||||
'subject_id' => 'required|integer|exists:claim_subjects,id',
|
||||
'customer_id' => 'sometimes|nullable|integer|exists:customers,id',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\ClaimMailTemplates;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ClaimMailTemplateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'brand_id' => 'required|exists:brands,id',
|
||||
'label' => 'required|string|min:3|max:255',
|
||||
'content' => 'required|string|min:3|max:500',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'brand_id' => trans('models.classes.brands'),
|
||||
'label' => trans('validation.custom.label'),
|
||||
'content' => trans('validation.attributes.content'),
|
||||
];
|
||||
}
|
||||
}
|
||||
66
app/Http/Requests/Bo/ClaimMessages/StoreMessageRequest.php
Normal file
66
app/Http/Requests/Bo/ClaimMessages/StoreMessageRequest.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\ClaimMessages;
|
||||
|
||||
use App\Enums\Claims\ClaimMessageType;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
|
||||
class StoreMessageRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
/** @var \App\Models\User $userModel */
|
||||
$userModel = auth('backend')->user();
|
||||
|
||||
$this->merge([
|
||||
'user_id' => $userModel->getKey(),
|
||||
'type' => ClaimMessageType::human->value(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'claim_id' => 'required|numeric|exists:claims,id',
|
||||
'user_id' => 'required|numeric|exists:users,id',
|
||||
'content' => 'required|string|between:3,255',
|
||||
'type' => ['required', new Enum(ClaimMessageType::class)],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array<string,\Illuminate\Contracts\Translation\Translator|string|array<mixed>|null>
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'claim_id' => trans('models.classes.claims'),
|
||||
'user_id' => trans('models.classes.users'),
|
||||
'content' => trans('validation.attributes.content'),
|
||||
'type' => trans('validation.custom.type'),
|
||||
];
|
||||
}
|
||||
}
|
||||
44
app/Http/Requests/Bo/ClaimMessages/UpdateMessageRequest.php
Normal file
44
app/Http/Requests/Bo/ClaimMessages/UpdateMessageRequest.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\ClaimMessages;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateMessageRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'claim_message_id' => 'required|numeric|exists:claim_messages,id',
|
||||
'content' => 'required|string|between:3,255',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array<string,\Illuminate\Contracts\Translation\Translator|string|array<mixed>|null>
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'claim_message_id' => trans('models.classes.claim_messages'),
|
||||
'content' => trans('validation.attributes.content'),
|
||||
];
|
||||
}
|
||||
}
|
||||
44
app/Http/Requests/Bo/ClaimSubjects/ClaimSubjectRequest.php
Normal file
44
app/Http/Requests/Bo/ClaimSubjects/ClaimSubjectRequest.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\ClaimSubjects;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ClaimSubjectRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'brand_id' => 'required|exists:brands,id',
|
||||
'label' => 'required|string|min:3|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'brand_id' => trans('models.classes.brands'),
|
||||
'label' => trans('validation.attributes.label'),
|
||||
];
|
||||
}
|
||||
}
|
||||
44
app/Http/Requests/Bo/Claims/SendClaimAnswerRequest.php
Normal file
44
app/Http/Requests/Bo/Claims/SendClaimAnswerRequest.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Claims;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SendClaimAnswerRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'claim_id' => 'required|numeric|exists:claims,id',
|
||||
'content' => 'required|string|between:3,500',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array<string,\Illuminate\Contracts\Translation\Translator|string|array<mixed>|null>
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'claim_id' => trans('models.classes.claims'),
|
||||
'content' => trans('validation.attributes.content'),
|
||||
];
|
||||
}
|
||||
}
|
||||
54
app/Http/Requests/Bo/Claims/UpdateClaimRequest.php
Normal file
54
app/Http/Requests/Bo/Claims/UpdateClaimRequest.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Claims;
|
||||
|
||||
use App\Enums\Claims\ClaimResponseType;
|
||||
use App\Enums\Claims\ClaimStatus;
|
||||
use App\Enums\Claims\ClaimType;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
|
||||
class UpdateClaimRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'brand_id' => 'required|numeric|exists:brands,id',
|
||||
'subject_id' => 'required|numeric|exists:claim_subjects,id',
|
||||
'type' => ['required', new Enum(ClaimType::class)],
|
||||
'status' => ['required', new Enum(ClaimStatus::class)],
|
||||
'response_type' => ['present', 'nullable', new Enum(ClaimResponseType::class)],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array<string,\Illuminate\Contracts\Translation\Translator|string|array<mixed>|null>
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'brand_id' => trans('models.classes.brands'),
|
||||
'subject_id' => trans('models.classes.claimsubjects'),
|
||||
'type' => trans('validation.custom.type'),
|
||||
'status' => trans('validation.custom.status'),
|
||||
'response_type' => trans('validation.custom.response_type'),
|
||||
];
|
||||
}
|
||||
}
|
||||
52
app/Http/Requests/Bo/PaginateModelsRequest.php
Normal file
52
app/Http/Requests/Bo/PaginateModelsRequest.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class PaginateModelsRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string,\Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'targetModel' => [
|
||||
'required',
|
||||
'string',
|
||||
'starts_with:App\\Models\\',
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function ($attribute, $value, $fail) {
|
||||
if (!class_exists($value)) {
|
||||
$fail("Le modèle spécifié n'existe pas.");
|
||||
return;
|
||||
}
|
||||
if (!is_subclass_of($value, \Illuminate\Database\Eloquent\Model::class)) {
|
||||
$fail("Le modèle spécifié n'est pas un modèle Eloquent.");
|
||||
}
|
||||
},
|
||||
],
|
||||
'page' => 'required|integer|min:1',
|
||||
'paginate' => 'required|integer|min:1',
|
||||
'fieldName' => 'required|string|alpha_dash|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array<string,\Illuminate\Contracts\Translation\Translator|string|array<mixed>|null>
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'targetModel' => trans('validation.custom.targetModel'),
|
||||
'page' => trans('validation.custom.page'),
|
||||
'paginate' => trans('validation.custom.paginate'),
|
||||
'fieldName' => trans('validation.custom.fieldName'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -18,18 +18,6 @@ class StoreQuestionRequest extends FormRequest
|
|||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'brand_id' => collect($this->brand)->pluck('id')->first()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -16,18 +16,6 @@ class StoreServiceRequest extends FormRequest
|
|||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'brand_id' => collect($this->brand)->pluck('id')->first()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
|
|
|
|||
34
app/Http/Requests/Bo/ThemeRequest.php
Normal file
34
app/Http/Requests/Bo/ThemeRequest.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo;
|
||||
|
||||
use App\Enums\Theme\BootstrapThemeEnum;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
|
||||
class ThemeRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string,\Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'theme' => ['required', new Enum(BootstrapThemeEnum::class)],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array<string,\Illuminate\Contracts\Translation\Translator|string|array<mixed>|null>
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'theme' => trans('validation.custom.theme'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,6 @@ namespace App\Http\Requests\Bo\Users;
|
|||
use App\Enums\Users\RoleEnum;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class StoreUserRequest extends FormRequest
|
||||
{
|
||||
|
|
@ -24,10 +23,11 @@ class StoreUserRequest extends FormRequest
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation()
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'published' => $this->published ? true : false
|
||||
'published' => $this->input('published') ? true : false,
|
||||
'brand_id' => $this->input('brand_id') ?: [],
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -39,19 +39,14 @@ class StoreUserRequest extends FormRequest
|
|||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'first_name' => 'required|string|min:3|max:255',
|
||||
'last_name' => 'required|string|min:3|max:255',
|
||||
'email' => 'required|email:rfc,strict,dns,spoof,filter|unique:users,email',
|
||||
'password' => [
|
||||
'required', 'required_with:password_confirmation', 'confirmed', 'max:255', Password::min(8)
|
||||
->letters()
|
||||
->mixedCase()
|
||||
->numbers()
|
||||
->symbols()
|
||||
->uncompromised()
|
||||
],
|
||||
'role' => ['required', new Enum(RoleEnum::class)],
|
||||
'published' => 'required|boolean',
|
||||
'first_name' => 'required|string|min:3|max:255',
|
||||
'last_name' => 'required|string|min:3|max:255',
|
||||
'email' => 'required|email:rfc,strict,dns,spoof,filter|unique:users,email',
|
||||
'role' => ['required', new Enum(RoleEnum::class)],
|
||||
'published' => 'required|boolean',
|
||||
'brand_id' => 'present|array',
|
||||
'brand_id.*' => 'sometimes|nullable|array',
|
||||
'brand_id.*.id' => 'sometimes|nullable|numeric|exists:brands,id',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -63,12 +58,14 @@ class StoreUserRequest extends FormRequest
|
|||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'first_name' => trans('validation.attributes.first_name'),
|
||||
'last_name' => trans('validation.attributes.last_name'),
|
||||
'email' => trans('validation.attributes.email'),
|
||||
'password' => trans('validation.attributes.password'),
|
||||
'role' => trans('validation.attributes.role'),
|
||||
'published' => trans('validation.custom.publication')
|
||||
'first_name' => trans('validation.attributes.first_name'),
|
||||
'last_name' => trans('validation.attributes.last_name'),
|
||||
'email' => trans('validation.attributes.email'),
|
||||
'role' => trans('validation.attributes.role'),
|
||||
'published' => trans('validation.custom.publication'),
|
||||
'brand_id' => trans('models.classes.brands'),
|
||||
'brand_id.*' => trans('models.classes.brands'),
|
||||
'brand_id.*.id' => trans('models.classes.brands'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
namespace App\Http\Requests\Bo\Users;
|
||||
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class UpdateUserRequest extends StoreUserRequest
|
||||
{
|
||||
/**
|
||||
|
|
@ -11,14 +9,11 @@ class UpdateUserRequest extends StoreUserRequest
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation()
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'published' => $this->published ? true : false,
|
||||
'password' => $this->password ? $this->password : $this->route('user')->password,
|
||||
'password_confirmation' => $this->password_confirmation ?
|
||||
$this->password_confirmation :
|
||||
$this->route('user')->password
|
||||
'published' => $this->input('published') ? true : false,
|
||||
'brand_id' => $this->input('brand_id') ?: [],
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -29,19 +24,15 @@ class UpdateUserRequest extends StoreUserRequest
|
|||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
/** @var \App\Models\User $userModel */
|
||||
$userModel = request()->route()->parameter('user');
|
||||
|
||||
return array_merge(parent::rules(), [
|
||||
'email' => [
|
||||
'email' => [
|
||||
'required',
|
||||
'string',
|
||||
'email:rfc,strict,dns,spoof,filter',
|
||||
'unique:users,email,' . $this->route('user')->id . ',id',
|
||||
],
|
||||
'password' => [
|
||||
'required', 'required_with:password_confirmation', 'confirmed', 'max:255', Password::min(8)
|
||||
->letters()
|
||||
->mixedCase()
|
||||
->numbers()
|
||||
->symbols()
|
||||
->uncompromised()
|
||||
'unique:users,email,' . $userModel->getKey(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
123
app/Listeners/AddClaimMessageSystem.php
Normal file
123
app/Listeners/AddClaimMessageSystem.php
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Enums\Claims\ClaimMessageType;
|
||||
use App\Events\ClaimModelChanged;
|
||||
use App\Models\ClaimMessage;
|
||||
|
||||
class AddClaimMessageSystem
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param \App\Events\ClaimModelChanged $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ClaimModelChanged $event): void
|
||||
{
|
||||
$message = $this->createClaimMessage($event);
|
||||
|
||||
// Assign content based on whether there is a custom message or default handling.
|
||||
$message->content = $event->content ? $event->content : $this->generateMessageContent($event);
|
||||
|
||||
$message->saveOrFail();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ClaimMessage instance.
|
||||
*
|
||||
* @param \App\Events\ClaimModelChanged $event
|
||||
* @return \App\Models\ClaimMessage
|
||||
*/
|
||||
private function createClaimMessage(ClaimModelChanged $event): ClaimMessage
|
||||
{
|
||||
return new ClaimMessage([
|
||||
'claim_id' => $event->claim->getKey(),
|
||||
'user_id' => null,
|
||||
'type' => ClaimMessageType::system,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the message content based on the event data.
|
||||
*
|
||||
* @param \App\Events\ClaimModelChanged $event
|
||||
* @return string
|
||||
*/
|
||||
private function generateMessageContent(ClaimModelChanged $event): string
|
||||
{
|
||||
// Check for Enum type and generate content accordingly.
|
||||
$castType = $event->claim->getCasts()[$event->field] ?? null;
|
||||
if ($castType && enum_exists($castType) && str_starts_with($castType, "App\\Enums\\Claims\\")) {
|
||||
return $this->generateEnumMessageContent($event);
|
||||
}
|
||||
|
||||
// Default field message content.
|
||||
return $this->generateDefaultFieldMessageContent($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate message content for Enum type fields.
|
||||
*
|
||||
* @param \App\Events\ClaimModelChanged $event
|
||||
* @return string
|
||||
*/
|
||||
private function generateEnumMessageContent(ClaimModelChanged $event): string
|
||||
{
|
||||
$enumLabel = $event->claim->{$event->field}->label();
|
||||
$enumColor = $event->claim->{$event->field}->color();
|
||||
$baseMessage = trans(':field est passé à', ['field' => $event->label]);
|
||||
|
||||
// If the user is available, include user details in the message.
|
||||
if ($event->user) {
|
||||
return sprintf(
|
||||
"<b>%s %s</b> %s <i class='badge' style='background-color:%s'>%s</i>",
|
||||
$event->user->first_name,
|
||||
$event->user->last_name,
|
||||
trans('a modifié le :field en', ['field' => $event->label]),
|
||||
$enumColor,
|
||||
$enumLabel,
|
||||
);
|
||||
}
|
||||
|
||||
// User is not available, return a simple enum change message.
|
||||
return sprintf(
|
||||
"%s : <i class='badge' style='background-color:%s'>%s</i>",
|
||||
$baseMessage,
|
||||
$enumColor,
|
||||
$enumLabel,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate message content for default field types.
|
||||
*
|
||||
* @param \App\Events\ClaimModelChanged $event
|
||||
* @return string
|
||||
*/
|
||||
private function generateDefaultFieldMessageContent(ClaimModelChanged $event): string
|
||||
{
|
||||
$field = $event->claim->{$event->field};
|
||||
$baseMessage = trans(':field est passé à', ['field' => $event->label]);
|
||||
$fieldLabel = $field->label ?? $field->name;
|
||||
|
||||
// If the user is available, include user details in the message.
|
||||
if ($event->user) {
|
||||
return sprintf(
|
||||
"<b>%s %s</b> %s <b>%s</b>",
|
||||
$event->user->first_name,
|
||||
$event->user->last_name,
|
||||
trans('a modifié le :field en', ['field' => $event->label]),
|
||||
$fieldLabel,
|
||||
);
|
||||
}
|
||||
|
||||
// User is not available, return a simple field change message.
|
||||
return sprintf(
|
||||
"%s : <b>%s</b>",
|
||||
$baseMessage,
|
||||
$fieldLabel,
|
||||
);
|
||||
}
|
||||
}
|
||||
70
app/Mail/ClaimAnswerMail.php
Normal file
70
app/Mail/ClaimAnswerMail.php
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Claim;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ClaimAnswerMail extends Mailable implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* The current claim.
|
||||
*
|
||||
* @var \App\Models\Claim
|
||||
*/
|
||||
protected $claimModel;
|
||||
|
||||
/**
|
||||
* The answer of the current claim.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $answer;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @param \App\Models\Claim $claimModel
|
||||
* @param string $answer
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Claim $claimModel, string $answer)
|
||||
{
|
||||
$this->claimModel = $claimModel;
|
||||
$this->answer = $answer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this
|
||||
->from("no-reply@{$this->claimModel->brand->domain}")
|
||||
->subject(sprintf(
|
||||
'Réponse réclamation %s - %s',
|
||||
$this->claimModel->reference,
|
||||
$this->claimModel->brand->name
|
||||
))
|
||||
->markdown('mail.send-claim-answer')
|
||||
->text('mail.send-claim-answer-plain')
|
||||
->with([
|
||||
'customHeader' => view('vendor.mail.html.header-claim-answer', [
|
||||
'brandModel' => $this->claimModel->brand,
|
||||
])->render(),
|
||||
'customFooter' => view('vendor.mail.html.footer-claim-answer', [
|
||||
'brandModel' => $this->claimModel->brand,
|
||||
])->render(),
|
||||
'claimModel' => $this->claimModel,
|
||||
'answer' => $this->answer,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ class ActivityLog extends Model
|
|||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected $casts = [
|
||||
'is_anonymous' => 'bool',
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace App\Models;
|
|||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/**
|
||||
* @property integer $id Id.
|
||||
|
|
@ -22,16 +23,74 @@ class Answer extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'answer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::created(function (self $model) {
|
||||
self::resetCache($model);
|
||||
});
|
||||
static::updated(function (self $model) {
|
||||
self::resetCache($model);
|
||||
});
|
||||
static::deleted(function (self $model) {
|
||||
self::resetCache($model);
|
||||
});
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Get all answers associated to the band.
|
||||
*
|
||||
* @param integer $questionModelKey
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getAllModelsFromQuestion(int $questionModelKey): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return self::getAnswers()->filter(
|
||||
fn($model) => $model->question->getKey() === $questionModelKey
|
||||
)->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all cache elements related to this model.
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function resetCache(self $model): void
|
||||
{
|
||||
$questionModelKey = $model->question->getKey();
|
||||
Cache::forget("question-{$questionModelKey}-answers");
|
||||
self::getAnswers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all answers.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getAnswers(): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return Cache::remember('answers', 86400, function () {
|
||||
return self::query()->orderBy('answer', 'ASC')->get();
|
||||
});
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Question BelongsTo relation.
|
||||
* Question belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -2,16 +2,21 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Traits\Models\ActivityLog;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Rennokki\QueryCache\Traits\QueryCacheable;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/**
|
||||
* @property integer $id Id.
|
||||
* @property string $name Name.
|
||||
* @property-read \Illuminate\Support\Carbon $created_at Created date.
|
||||
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
|
||||
* @property integer $id Brand id.
|
||||
* @property string $name Brand name.
|
||||
* @property string $logo Brand logo.
|
||||
* @property string $url Brand url link.
|
||||
* @property string $url_claim Brand associative url claim.
|
||||
* @property string $domain Brand domain.
|
||||
* @property-read \Illuminate\Support\Carbon $created_at Brand created date.
|
||||
* @property-read \Illuminate\Support\Carbon $updated_at Brand updated date.
|
||||
*
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<App\Models\Service>
|
||||
* $services Service HasMany relation.
|
||||
|
|
@ -28,51 +33,20 @@ class Brand extends Model
|
|||
{
|
||||
use ActivityLog;
|
||||
use HasFactory;
|
||||
use QueryCacheable;
|
||||
|
||||
/**
|
||||
* The timeout cache for this model.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $cacheFor = 0;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'logo',
|
||||
'url',
|
||||
'url_claim',
|
||||
'domain',
|
||||
];
|
||||
|
||||
/**
|
||||
* Brand
|
||||
*
|
||||
* @param array $attributes
|
||||
*/
|
||||
public function __construct(array $attributes = [])
|
||||
{
|
||||
$this->cacheFor = config('api.servicesDBCache') * 60;
|
||||
|
||||
parent::__construct($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base cache tags that will be present
|
||||
* on all queries.
|
||||
*
|
||||
* ! This is used to flush caching
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getCacheBaseTags(): array
|
||||
{
|
||||
return [
|
||||
'crm_brands',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
|
|
@ -81,71 +55,16 @@ class Brand extends Model
|
|||
protected static function booted(): void
|
||||
{
|
||||
static::created(function () {
|
||||
// * Flush Eloquent cache.
|
||||
self::flushQueryCache();
|
||||
self::resetCache();
|
||||
});
|
||||
static::updated(function () {
|
||||
// * Flush Eloquent cache.
|
||||
self::flushQueryCache();
|
||||
self::resetCache();
|
||||
});
|
||||
static::deleted(function () {
|
||||
// * Flush Eloquent cache.
|
||||
self::flushQueryCache();
|
||||
self::resetCache();
|
||||
});
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Service hasMany relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function services(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Service::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Question hasMany relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function questions(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Question::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* CustomerInfo hasMany relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function customerInfos(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(CustomerInfo::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* ServiceStat hasMany relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function servicesStats(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(ServiceStat::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* SingleOptin hasMany relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function singleOptins(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(SingleOptin::class);
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
|
|
@ -167,4 +86,141 @@ class Brand extends Model
|
|||
{
|
||||
return $this->customerInfos()->where('opt_in', 1)->count() + $this->singleOptins()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all brands associated to the auth user.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getUserAssociatedBrands(): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
/** @var \App\Models\User $userModel */
|
||||
$userModel = auth('backend')->user();
|
||||
$brandModels = self::getBrands();
|
||||
|
||||
if ($userModel->role->equals(RoleEnum::marketing)) {
|
||||
$brandIds = $userModel->brands->modelKeys();
|
||||
|
||||
$brandModels = $brandModels->filter(function ($brand) use ($brandIds) {
|
||||
return in_array($brand->getKey(), $brandIds);
|
||||
})->values();
|
||||
}
|
||||
|
||||
return $brandModels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all cache elements related to this model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function resetCache(): void
|
||||
{
|
||||
Cache::forget('brands');
|
||||
self::getBrands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all brands.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getBrands(): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return Cache::remember('brands', 86400, function () {
|
||||
return self::query()->orderBy('name', 'ASC')->get();
|
||||
});
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Service has many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function services(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Service::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Question has many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function questions(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Question::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* CustomerInfo has many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function customerInfos(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(CustomerInfo::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* ServiceStat has many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function servicesStats(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(ServiceStat::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* SingleOptin has many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function singleOptins(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(SingleOptin::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Users many to many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Brand::class, 'brand_users', 'brand_id', 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Claim has many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function claims(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Claim::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* ClaimSubject has many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function claimSubjects(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(ClaimSubject::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* ClaimMailTemplate has many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function claimMailTemplates(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(ClaimMailTemplate::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class BrandStat extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'active',
|
||||
|
|
@ -42,7 +42,7 @@ class BrandStat extends Model
|
|||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
public $casts = [
|
||||
'created_at' => 'date',
|
||||
|
|
@ -65,7 +65,7 @@ class BrandStat extends Model
|
|||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Brand hasMany relation.
|
||||
* Brand belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
|
|
|||
212
app/Models/Claim.php
Normal file
212
app/Models/Claim.php
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Claims\ClaimResponseType;
|
||||
use App\Enums\Claims\ClaimStatus;
|
||||
use App\Enums\Claims\ClaimType;
|
||||
use App\Events\ClaimModelChanged;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property integer $id Claim id.
|
||||
* @property string $reference Claim reference.
|
||||
* @property string $first_name Claimant\'s first name.
|
||||
* @property string $last_name Claimant\'s last name.
|
||||
* @property string $email Claimant\'s email.
|
||||
* @property string|null $address Claimant\'s address.
|
||||
* @property string|null $city Claimant\'s city.
|
||||
* @property string|null $postcode Claimant\'s postcode.
|
||||
* @property string|null $file Claimant\'s file.
|
||||
* @property string $message Claimant\'s message.
|
||||
* @property \App\Enums\Claims\ClaimResponseType $response_type Claim type (ClaimResponseType enum).
|
||||
* @property \App\Enums\Claims\ClaimStatus $status Claim status (ClaimStatus enum).
|
||||
* @property \App\Enums\Claims\ClaimType $type Claim type (ClaimType enum).
|
||||
* @property \App\Models\Brand $brand_id Claim associated Brand.
|
||||
* @property \App\Models\ClaimSubject $subject_id Claim associated Subject.
|
||||
* @property \App\Models\Customer|null $customer_id Claim associated Customer.
|
||||
* @property-read \Illuminate\Support\Carbon $created_at Claim created date.
|
||||
* @property-read \Illuminate\Support\Carbon $updated_at Claim updated date.
|
||||
*/
|
||||
class Claim extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'reference',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'email',
|
||||
'address',
|
||||
'city',
|
||||
'postcode',
|
||||
'file',
|
||||
'message',
|
||||
'response_type',
|
||||
'status',
|
||||
'type',
|
||||
'brand_id',
|
||||
'subject_id',
|
||||
'customer_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected $casts = [
|
||||
'response_type' => ClaimResponseType::class,
|
||||
'status' => ClaimStatus::class,
|
||||
'type' => ClaimType::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::created(function (self $model) {
|
||||
$model->reference = self::encodeIntegerToBase36($model->getKey());
|
||||
$model->saveOrFail();
|
||||
});
|
||||
static::updated(function (self $model) {
|
||||
$user = auth()->user();
|
||||
if (!$user instanceof \App\Models\User) {
|
||||
$user = null;
|
||||
}
|
||||
|
||||
if (isset($model->getChanges()['brand_id'])) {
|
||||
event(new ClaimModelChanged(
|
||||
$model->load('brand'),
|
||||
'brand',
|
||||
Str::singular(trans('models.classes.brands')),
|
||||
$user,
|
||||
));
|
||||
}
|
||||
if (isset($model->getChanges()['subject_id'])) {
|
||||
event(new ClaimModelChanged(
|
||||
$model->load('claimSubject'),
|
||||
'claimSubject',
|
||||
trans('models.classes.claimsubjects'),
|
||||
$user,
|
||||
));
|
||||
}
|
||||
if (isset($model->getChanges()['status'])) {
|
||||
event(new ClaimModelChanged(
|
||||
$model,
|
||||
'status',
|
||||
trans('validation.custom.status'),
|
||||
$user,
|
||||
));
|
||||
}
|
||||
if (isset($model->getChanges()['type'])) {
|
||||
event(new ClaimModelChanged(
|
||||
$model,
|
||||
'type',
|
||||
trans('validation.custom.type'),
|
||||
$user,
|
||||
));
|
||||
}
|
||||
if (
|
||||
isset($model->getChanges()['response_type'])
|
||||
&& !$model->response_type->equals(ClaimResponseType::manual)
|
||||
) {
|
||||
event(new ClaimModelChanged(
|
||||
$model,
|
||||
'response_type',
|
||||
trans('validation.custom.response_type'),
|
||||
$user,
|
||||
));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Brand belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function brand(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Brand::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* ClaimSubject subject belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function claimSubject(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ClaimSubject::class, 'subject_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Customer subject belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function customer(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Customer::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* ClaimMessage has many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function claimMessages(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(ClaimMessage::class);
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Convert the integer to base 36 and make uppercase.
|
||||
*
|
||||
* @param integer $int
|
||||
* @return string
|
||||
*/
|
||||
public static function encodeIntegerToBase36(int $int): string
|
||||
{
|
||||
return strtoupper(base_convert($int, 10, 36));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert back to base 10 from base 36, case insensitive.
|
||||
*
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
public static function decodeBase36ToInteger(string $str): string
|
||||
{
|
||||
return base_convert(strtolower($str), 36, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get formated address.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormatedAddress(): string
|
||||
{
|
||||
return implode(', ', array_filter([
|
||||
$this->address,
|
||||
trim(implode(' ', array_filter([$this->postcode, $this->city])))
|
||||
]));
|
||||
}
|
||||
}
|
||||
81
app/Models/ClaimMailTemplate.php
Normal file
81
app/Models/ClaimMailTemplate.php
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/**
|
||||
* @property integer $id Mail template id.
|
||||
* @property string $label Mail template label.
|
||||
* @property string $content Mail template content.
|
||||
* @property \App\Models\Brand $brand_id Mail template associated Brand.
|
||||
* @property-read \Illuminate\Support\Carbon $created_at Mail template created date.
|
||||
* @property-read \Illuminate\Support\Carbon $updated_at Mail template updated date.
|
||||
*/
|
||||
class ClaimMailTemplate extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'label',
|
||||
'content',
|
||||
'brand_id',
|
||||
];
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Get all templates associated to the band.
|
||||
*
|
||||
* @param integer $brandModelKey
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getAllModelsFromBrand(int $brandModelKey): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return self::getTemplates()->filter(
|
||||
fn($model) => $model->brand->getKey() === $brandModelKey
|
||||
)->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all cache elements related to this model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function resetCache(): void
|
||||
{
|
||||
Cache::forget('templates');
|
||||
self::getTemplates();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all templates.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getTemplates(): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return Cache::remember('templates', 86400, function () {
|
||||
return self::query()->orderBy('label', 'ASC')->get();
|
||||
});
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Brand belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function brand(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Brand::class);
|
||||
}
|
||||
}
|
||||
119
app/Models/ClaimMessage.php
Normal file
119
app/Models/ClaimMessage.php
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Claims\ClaimMessageType;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/**
|
||||
* @property integer $id Subject id.
|
||||
* @property string $label Subject label.
|
||||
* @property \App\Models\Claim $claim_id Subject associated Claim.
|
||||
* @property-read \Illuminate\Support\Carbon $created_at Subject created date.
|
||||
* @property-read \Illuminate\Support\Carbon $updated_at Subject updated date.
|
||||
*/
|
||||
class ClaimMessage extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'content',
|
||||
'type',
|
||||
'claim_id',
|
||||
'user_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected $casts = [
|
||||
'type' => ClaimMessageType::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::created(function () {
|
||||
self::resetCache();
|
||||
});
|
||||
static::updated(function () {
|
||||
self::resetCache();
|
||||
});
|
||||
static::deleted(function () {
|
||||
self::resetCache();
|
||||
});
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Get all brands associated to the auth user.
|
||||
*
|
||||
* @param integer $claimModelKey
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getAllModelsFromClaim(int $claimModelKey): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return self::getClaimMessages()->filter(
|
||||
fn($model) => $model->claim->getKey() === $claimModelKey
|
||||
)->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all cache elements related to this model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function resetCache(): void
|
||||
{
|
||||
Cache::forget('claimMessages');
|
||||
self::getClaimMessages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all brands.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getClaimMessages(): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return Cache::remember('claimMessages', 86400, function () {
|
||||
return self::query()->with('user')->orderby('created_at', 'ASC')->get();
|
||||
});
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Claim belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function claim(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Claim::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* User belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
89
app/Models/ClaimSubject.php
Normal file
89
app/Models/ClaimSubject.php
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/**
|
||||
* @property integer $id Subject id.
|
||||
* @property string $label Subject label.
|
||||
* @property \App\Models\Brand $brand_id Subject associated Brand.
|
||||
* @property-read \Illuminate\Support\Carbon $created_at Subject created date.
|
||||
* @property-read \Illuminate\Support\Carbon $updated_at Subject updated date.
|
||||
*/
|
||||
class ClaimSubject extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'label',
|
||||
'brand_id',
|
||||
];
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Get all subjects associated to the band.
|
||||
*
|
||||
* @param integer $brandModelKey
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getAllModelsFromBrand(int $brandModelKey): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return self::getSubjects()->filter(
|
||||
fn($model) => $model->brand->getKey() === $brandModelKey
|
||||
)->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all cache elements related to this model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function resetCache(): void
|
||||
{
|
||||
Cache::forget('subjects');
|
||||
self::getSubjects();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all subjects.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getSubjects(): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return Cache::remember('subjects', 86400, function () {
|
||||
return self::query()->orderBy('label', 'ASC')->get();
|
||||
});
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Brand belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function brand(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Brand::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Claim has many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function claims(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Claim::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ class Customer extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'email',
|
||||
|
|
@ -45,7 +45,7 @@ class Customer extends Model
|
|||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* CustomerInfo hasMany relation.
|
||||
* CustomerInfo has many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
|
|
@ -55,7 +55,7 @@ class Customer extends Model
|
|||
}
|
||||
|
||||
/**
|
||||
* CustomerLogin hasMany relation.
|
||||
* CustomerLogin has many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
|
|
@ -65,7 +65,7 @@ class Customer extends Model
|
|||
}
|
||||
|
||||
/**
|
||||
* CustomerOptInHistory hasMany relation.
|
||||
* CustomerOptInHistory has many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
|
|
@ -75,7 +75,7 @@ class Customer extends Model
|
|||
}
|
||||
|
||||
/**
|
||||
* Customer Brand belongsToMany relation.
|
||||
* Customer Brand belongs to many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
|
|
@ -94,6 +94,16 @@ class Customer extends Model
|
|||
return $this->morphToMany(Answer::class, 'model', 'model_answer', 'model_id', 'answer_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Claim has many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function claims(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Claim::class);
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class CustomerInfo extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'firstname',
|
||||
|
|
@ -54,7 +54,7 @@ class CustomerInfo extends Model
|
|||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected $casts = [
|
||||
'country' => Country::class,
|
||||
|
|
@ -83,7 +83,7 @@ class CustomerInfo extends Model
|
|||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Customer BelongsTo relation.
|
||||
* Customer belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
|
@ -93,7 +93,7 @@ class CustomerInfo extends Model
|
|||
}
|
||||
|
||||
/**
|
||||
* Brand BelongsTo relation.
|
||||
* Brand belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -23,28 +23,28 @@ class CustomerLogin extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The model's attributes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'status' => false,
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The model's attributes.
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected $attributes = [
|
||||
'status' => false,
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected $casts = [
|
||||
'status' => 'bool',
|
||||
|
|
@ -73,7 +73,7 @@ class CustomerLogin extends Model
|
|||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Customer BelongsTo relation.
|
||||
* Customer belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
|
@ -83,7 +83,7 @@ class CustomerLogin extends Model
|
|||
}
|
||||
|
||||
/**
|
||||
* Brand BelongsTo relation.
|
||||
* Brand belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class CustomerOptInHistory extends Model
|
|||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected $casts = [
|
||||
'new_value' => 'bool',
|
||||
|
|
@ -39,7 +39,7 @@ class CustomerOptInHistory extends Model
|
|||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Customer BelongsTo relation.
|
||||
* Customer belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
|
@ -49,7 +49,7 @@ class CustomerOptInHistory extends Model
|
|||
}
|
||||
|
||||
/**
|
||||
* Brand BelongsTo relation.
|
||||
* Brand belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ namespace App\Models;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property integer $answer_id
|
||||
* @property integer $model_id
|
||||
* @property string $model_type
|
||||
* @property-read \Illuminate\Support\Carbon $created_at
|
||||
* @property integer $answer_id
|
||||
* @property integer $model_id
|
||||
* @property string $model_type
|
||||
* @property-read \Illuminate\Support\Carbon $created_at
|
||||
*
|
||||
* @property-read \App\Models\Answer $answer
|
||||
* @property-read \Illuminate\Database\Eloquent\Model $model
|
||||
* @property \App\Models\Answer $answer
|
||||
* @property \Illuminate\Database\Eloquent\Model $model
|
||||
*/
|
||||
class ModelAnswer extends Model
|
||||
{
|
||||
|
|
@ -22,6 +22,13 @@ class ModelAnswer extends Model
|
|||
*/
|
||||
protected $table = 'model_answer';
|
||||
|
||||
/**
|
||||
* The primary key for the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = null;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
|
|
@ -59,7 +66,7 @@ class ModelAnswer extends Model
|
|||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function answer()
|
||||
public function answer(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Answer::class);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use App\Enums\QuestionType;
|
|||
use App\Traits\Models\ActivityLog;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/**
|
||||
* @property integer $id Id.
|
||||
|
|
@ -26,7 +27,7 @@ class Question extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'question',
|
||||
|
|
@ -37,16 +38,74 @@ class Question extends Model
|
|||
/**
|
||||
* Map attribute names to enum classes.
|
||||
*
|
||||
* @var array
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected $casts = [
|
||||
'type' => QuestionType::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::created(function (self $model) {
|
||||
self::resetCache($model->getKey());
|
||||
});
|
||||
static::updated(function (self $model) {
|
||||
self::resetCache($model->getKey());
|
||||
});
|
||||
static::deleted(function (self $model) {
|
||||
self::resetCache($model->getKey());
|
||||
});
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Get all questions associated to the band.
|
||||
*
|
||||
* @param integer $brandModelKey
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getAllModelsFromBrand(int $brandModelKey): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return self::getQuestions()->filter(
|
||||
fn($model) => $model->brand->getKey() === $brandModelKey
|
||||
)->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all cache elements related to this model.
|
||||
*
|
||||
* @param integer $modelKey
|
||||
* @return void
|
||||
*/
|
||||
private static function resetCache(int $modelKey): void
|
||||
{
|
||||
Cache::forget('questions');
|
||||
Cache::forget("question-{$modelKey}-answers");
|
||||
self::getQuestions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all questions.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getQuestions(): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return Cache::remember('questions', 86400, function () {
|
||||
return self::query()->orderBy('question', 'ASC')->get();
|
||||
});
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Brand BelongsTo relation.
|
||||
* Brand belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
|
@ -56,7 +115,7 @@ class Question extends Model
|
|||
}
|
||||
|
||||
/**
|
||||
* Answer Has many relation.
|
||||
* Answer has many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
use Rennokki\QueryCache\Traits\QueryCacheable;
|
||||
|
||||
/**
|
||||
* @property integer $id Id.
|
||||
|
|
@ -32,19 +32,11 @@ class Service extends Model
|
|||
{
|
||||
use ActivityLog;
|
||||
use HasFactory;
|
||||
use QueryCacheable;
|
||||
|
||||
/**
|
||||
* The timeout cache for this model
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $cacheFor = 0;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
|
|
@ -54,24 +46,12 @@ class Service extends Model
|
|||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected $casts = [
|
||||
'bearer_token_date' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Service.
|
||||
*
|
||||
* @param array $attributes
|
||||
*/
|
||||
public function __construct(array $attributes = [])
|
||||
{
|
||||
parent::__construct($attributes);
|
||||
$this->cacheFor = config('api.servicesDBCache') * 60;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
|
|
@ -86,23 +66,20 @@ class Service extends Model
|
|||
}
|
||||
});
|
||||
static::created(function () {
|
||||
// * Flush Eloquent cache.
|
||||
self::flushQueryCache();
|
||||
self::resetCache();
|
||||
});
|
||||
static::updated(function () {
|
||||
// * Flush Eloquent cache.
|
||||
self::flushQueryCache();
|
||||
self::resetCache();
|
||||
});
|
||||
static::deleted(function () {
|
||||
// * Flush Eloquent cache.
|
||||
self::flushQueryCache();
|
||||
self::resetCache();
|
||||
});
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Brand BelongsTo relation.
|
||||
* Brand belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
|
@ -112,7 +89,7 @@ class Service extends Model
|
|||
}
|
||||
|
||||
/**
|
||||
* ServiceStat hasMany relation.
|
||||
* ServiceStat has many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
|
|
@ -123,21 +100,6 @@ class Service extends Model
|
|||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Set the base cache tags that will be present
|
||||
* on all queries.
|
||||
*
|
||||
* ! This is used to flush caching
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getCacheBaseTags(): array
|
||||
{
|
||||
return [
|
||||
'crm_services',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates new bearer token.
|
||||
*
|
||||
|
|
@ -184,25 +146,21 @@ class Service extends Model
|
|||
*/
|
||||
public static function getFromBearerToken(string $bearerToken): self
|
||||
{
|
||||
$services = static::all();
|
||||
/** @var \App\Models\Service $service */
|
||||
foreach ($services as $service) {
|
||||
$tokenEquals = false;
|
||||
// * Keep compatibility with V2.
|
||||
if (!Hash::needsRehash($bearerToken)) {
|
||||
$tokenEquals = Hash::check($bearerToken, $service->bearer_token);
|
||||
} else {
|
||||
$tokenEquals = $bearerToken === $service->bearer_token;
|
||||
}
|
||||
if ($service->bearer_token and $tokenEquals) {
|
||||
return $service->load([
|
||||
'brand' => function ($query) use ($service) {
|
||||
return $query->cacheTags(["service:{$service->id}:brand"]);
|
||||
},
|
||||
]);
|
||||
$service = static::getServices()->first(function ($service) use ($bearerToken) {
|
||||
if (! $service->bearer_token) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !Hash::needsRehash($bearerToken)
|
||||
? Hash::check($bearerToken, $service->bearer_token)
|
||||
: $bearerToken === $service->bearer_token;
|
||||
});
|
||||
|
||||
if (! $service) {
|
||||
throw new ModelNotFoundException('Could not find service from Service Token');
|
||||
}
|
||||
throw new ModelNotFoundException('Could not find service from Service Token');
|
||||
|
||||
return $service->load('brand');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -255,4 +213,27 @@ class Service extends Model
|
|||
// ! Très important hash_equals https://fr.wikipedia.org/wiki/Attaque_temporelle
|
||||
return \hash_equals($calculatedHash, $request->signature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all cache elements related to this model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function resetCache(): void
|
||||
{
|
||||
Cache::forget('services');
|
||||
self::getServices();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all services.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getServices(): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return Cache::remember('services', 86400, function () {
|
||||
return self::query()->orderBy('name', 'ASC')->get();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class ServiceStat extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'date',
|
||||
|
|
@ -33,7 +33,7 @@ class ServiceStat extends Model
|
|||
/**
|
||||
* The model's attributes.
|
||||
*
|
||||
* @var array
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected $attributes = [
|
||||
'nb_calls' => 0,
|
||||
|
|
@ -42,7 +42,7 @@ class ServiceStat extends Model
|
|||
/**
|
||||
* Map attribute names to enum classes.
|
||||
*
|
||||
* @var array
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected $casts = [
|
||||
'date' => 'date',
|
||||
|
|
@ -51,7 +51,7 @@ class ServiceStat extends Model
|
|||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Brand BelongsTo relation.
|
||||
* Brand belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
|
@ -61,7 +61,7 @@ class ServiceStat extends Model
|
|||
}
|
||||
|
||||
/**
|
||||
* Service BelongsTo relation.
|
||||
* Service belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class SingleOptin extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'email',
|
||||
|
|
@ -65,7 +65,7 @@ class SingleOptin extends Model
|
|||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Brand BelongsTo relation.
|
||||
* Brand belongs to relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class User extends Authenticatable
|
|||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected $casts = [
|
||||
'role' => RoleEnum::class,
|
||||
|
|
@ -112,4 +112,16 @@ class User extends Authenticatable
|
|||
AuthorizationException::class
|
||||
);
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Brands many to many relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function brands(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Brand::class, 'brand_users', 'user_id', 'brand_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
32
app/Policies/ActivityLogPolicy.php
Normal file
32
app/Policies/ActivityLogPolicy.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserStaticRules;
|
||||
|
||||
class ActivityLogPolicy
|
||||
{
|
||||
/**
|
||||
* View a Log.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function view(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* ViewAny a Log.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewAny(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Policies\Rules\UserStaticRules as USR;
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserStaticRules;
|
||||
|
||||
class AnswerPolicy
|
||||
{
|
||||
|
|
@ -13,46 +15,50 @@ class AnswerPolicy
|
|||
*/
|
||||
public function view(): bool
|
||||
{
|
||||
return USR::noOne();
|
||||
return UserStaticRules::noOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* ViewAny an Answer.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewAny(): bool
|
||||
public function viewAny(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an Answer.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function create(): bool
|
||||
public function create(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an Answer.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function update(): bool
|
||||
public function update(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an Answer.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function delete(): bool
|
||||
public function delete(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Policies\Rules\UserStaticRules as USR;
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserStaticRules;
|
||||
|
||||
class BrandPolicy
|
||||
{
|
||||
|
|
@ -13,37 +15,40 @@ class BrandPolicy
|
|||
*/
|
||||
public function view(): bool
|
||||
{
|
||||
return USR::noOne();
|
||||
return UserStaticRules::noOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* ViewAny a Brand.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewAny(): bool
|
||||
public function viewAny(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Brand.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function create(): bool
|
||||
public function create(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a Brand.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function update(): bool
|
||||
public function update(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -53,6 +58,6 @@ class BrandPolicy
|
|||
*/
|
||||
public function delete(): bool
|
||||
{
|
||||
return USR::noOne();
|
||||
return UserStaticRules::noOne();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
109
app/Policies/ClaimMailTemplatePolicy.php
Normal file
109
app/Policies/ClaimMailTemplatePolicy.php
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Models\ClaimMailTemplate;
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserStaticRules;
|
||||
|
||||
class ClaimMailTemplatePolicy
|
||||
{
|
||||
/**
|
||||
* ViewAny a claim subject.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewAny(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::marketing);
|
||||
}
|
||||
|
||||
/**
|
||||
* View a claim subject.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @param \App\Models\ClaimMailTemplate $claim_mail_template
|
||||
* @return boolean
|
||||
*/
|
||||
public function view(User $authUser, ClaimMailTemplate $claim_mail_template): bool
|
||||
{
|
||||
return $this->checkOnlyMinAdminOrInUserBrands($authUser, $claim_mail_template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a claim subject.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function create(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::marketing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a claim subject.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function store(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::marketing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a claim subject.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @param \App\Models\ClaimMailTemplate $claim_mail_template
|
||||
* @return boolean
|
||||
*/
|
||||
public function edit(User $authUser, ClaimMailTemplate $claim_mail_template): bool
|
||||
{
|
||||
return $this->checkOnlyMinAdminOrInUserBrands($authUser, $claim_mail_template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a claim subject.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @param \App\Models\ClaimMailTemplate $claim_mail_template
|
||||
* @return boolean
|
||||
*/
|
||||
public function update(User $authUser, ClaimMailTemplate $claim_mail_template): bool
|
||||
{
|
||||
return $this->checkOnlyMinAdminOrInUserBrands($authUser, $claim_mail_template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a claim subject.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @param \App\Models\ClaimMailTemplate $claim_mail_template
|
||||
* @return boolean
|
||||
*/
|
||||
public function delete(User $authUser, ClaimMailTemplate $claim_mail_template): bool
|
||||
{
|
||||
return $this->checkOnlyMinAdminOrInUserBrands($authUser, $claim_mail_template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the user an access a specific resource.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @param \App\Models\ClaimMailTemplate $claim_mail_template
|
||||
* @return boolean
|
||||
*/
|
||||
private function checkOnlyMinAdminOrInUserBrands(User $authUser, ClaimMailTemplate $claim_mail_template): bool
|
||||
{
|
||||
$userBrandModelKeys = $authUser->brands->modelKeys();
|
||||
$claimMailTemplateModelKey = $claim_mail_template->brand->getKey();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin) || (
|
||||
UserStaticRules::atLeastRole($authUser, RoleEnum::marketing)
|
||||
&& \in_array($claimMailTemplateModelKey, $userBrandModelKeys)
|
||||
);
|
||||
}
|
||||
}
|
||||
51
app/Policies/ClaimMessagePolicy.php
Normal file
51
app/Policies/ClaimMessagePolicy.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use App\Policies\Rules\UserStaticRules as USR;
|
||||
|
||||
class ClaimMessagePolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* View a Claim Message.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function view(): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* View any a Claim Message.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewAny(): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a Claim Message.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function store(): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a Claim Message.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function update(): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
}
|
||||
}
|
||||
105
app/Policies/ClaimPolicy.php
Normal file
105
app/Policies/ClaimPolicy.php
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use App\Policies\Rules\UserStaticRules as USR;
|
||||
use App\Policies\Rules\UserStaticRules;
|
||||
|
||||
class ClaimPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* View a Claim.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function view(): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* View any a Claim.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewAny(): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* Preview a Claim.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function preview(): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a Claim.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function update(): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the associated brand of the model.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function updateBrand(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the associated subject of the model.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function updateSubject(): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a Claim.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function updateType(): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a Claim.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function updateStatus(): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a Claim.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function updateResponseType(): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
}
|
||||
}
|
||||
87
app/Policies/ClaimSubjectPolicy.php
Normal file
87
app/Policies/ClaimSubjectPolicy.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserStaticRules;
|
||||
|
||||
class ClaimSubjectPolicy
|
||||
{
|
||||
/**
|
||||
* ViewAny a claim subject.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewAny(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* View a claim subject.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function view(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a claim subject.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function create(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a claim subject.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function store(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a claim subject.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function edit(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a claim subject.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function update(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a claim subject.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function delete(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Service;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use App\Policies\Rules\UserStaticRules as USR;
|
||||
use App\Policies\Rules\UserStaticRules;
|
||||
|
||||
class CustomerPolicy
|
||||
{
|
||||
|
|
@ -14,21 +16,23 @@ class CustomerPolicy
|
|||
/**
|
||||
* View a Customer.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function view(): bool
|
||||
public function view(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* View any a Customer.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewAny(): bool
|
||||
public function viewAny(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -38,7 +42,7 @@ class CustomerPolicy
|
|||
*/
|
||||
public function create(): bool
|
||||
{
|
||||
return USR::noOne();
|
||||
return UserStaticRules::noOne();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -48,17 +52,18 @@ class CustomerPolicy
|
|||
*/
|
||||
public function update(): bool
|
||||
{
|
||||
return USR::noOne();
|
||||
return UserStaticRules::noOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a Customer.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function delete(): bool
|
||||
public function delete(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -72,4 +77,15 @@ class CustomerPolicy
|
|||
{
|
||||
return !\is_null($customer->login($service->brand));
|
||||
}
|
||||
|
||||
/**
|
||||
* Export Customers.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function export(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,60 +2,67 @@
|
|||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Models\Question;
|
||||
use App\Models\Service;
|
||||
use App\Policies\Rules\UserStaticRules as USR;
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserStaticRules;
|
||||
|
||||
class QuestionPolicy
|
||||
{
|
||||
/**
|
||||
* View a Question.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function view(): bool
|
||||
public function view(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* ViewAny a Question.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewAny(): bool
|
||||
public function viewAny(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Question.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function create(): bool
|
||||
public function create(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a Question.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function update(): bool
|
||||
public function update(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a Question.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function delete(): bool
|
||||
public function delete(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -69,4 +76,15 @@ class QuestionPolicy
|
|||
{
|
||||
return $service->brand->id === $question->brand_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export Customers.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function export(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,48 +2,54 @@
|
|||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Policies\Rules\UserStaticRules as USR;
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserStaticRules;
|
||||
|
||||
class ServicePolicy
|
||||
{
|
||||
/**
|
||||
* View an Answer.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function view(): bool
|
||||
public function view(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* ViewAny an Service.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewAny(): bool
|
||||
public function viewAny(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an Service.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function create(): bool
|
||||
public function create(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an Service.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function update(): bool
|
||||
public function update(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -53,6 +59,6 @@ class ServicePolicy
|
|||
*/
|
||||
public function delete(): bool
|
||||
{
|
||||
return USR::noOne();
|
||||
return UserStaticRules::noOne();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Policies\Rules\UserStaticRules as USR;
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserStaticRules;
|
||||
|
||||
class SingleOptinPolicy
|
||||
{
|
||||
|
|
@ -13,17 +15,18 @@ class SingleOptinPolicy
|
|||
*/
|
||||
public function view(): bool
|
||||
{
|
||||
return USR::noOne();
|
||||
return UserStaticRules::noOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* ViewAny an Answer.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewAny(): bool
|
||||
public function viewAny(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -33,7 +36,7 @@ class SingleOptinPolicy
|
|||
*/
|
||||
public function create(): bool
|
||||
{
|
||||
return USR::noOne();
|
||||
return UserStaticRules::noOne();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -43,16 +46,17 @@ class SingleOptinPolicy
|
|||
*/
|
||||
public function update(): bool
|
||||
{
|
||||
return USR::noOne();
|
||||
return UserStaticRules::noOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an Answer.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function delete(): bool
|
||||
public function delete(User $authUser): bool
|
||||
{
|
||||
return USR::everyOne();
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
43
app/Policies/StatisticPolicy.php
Normal file
43
app/Policies/StatisticPolicy.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserStaticRules;
|
||||
|
||||
class StatisticPolicy
|
||||
{
|
||||
/**
|
||||
* View stats by brand.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewStatsByBrand(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* View by question.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewByQuestion(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers by days.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function answersByDays(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ class UserPolicy
|
|||
*/
|
||||
public function viewAny(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -28,7 +28,7 @@ class UserPolicy
|
|||
*/
|
||||
public function view(User $authUser, User $user): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor) and
|
||||
UserStaticRules::atLeastRole($authUser, $user->role);
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ class UserPolicy
|
|||
*/
|
||||
public function create(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -53,7 +53,7 @@ class UserPolicy
|
|||
public function update(User $authUser, User $user): bool
|
||||
{
|
||||
return $authUser->getRouteKey() === $user->getRouteKey() or
|
||||
(UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and
|
||||
(UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor) and
|
||||
UserStaticRules::atLeastRole($authUser, $user->role));
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ class UserPolicy
|
|||
public function delete(User $authUser, User $user): bool
|
||||
{
|
||||
return $authUser->getRouteKey() !== $user->getRouteKey() and
|
||||
UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and
|
||||
UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor) and
|
||||
UserStaticRules::atLeastRole($authUser, $user->role);
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ class UserPolicy
|
|||
public function restore(User $authUser, User $user): bool
|
||||
{
|
||||
return $authUser->getRouteKey() !== $user->getRouteKey() and
|
||||
UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and
|
||||
UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor) and
|
||||
UserStaticRules::atLeastRole($authUser, $user->role);
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ class UserPolicy
|
|||
public function forceDelete(User $authUser, User $user): bool
|
||||
{
|
||||
return $authUser->getRouteKey() !== $user->getRouteKey() and
|
||||
UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and
|
||||
UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor) and
|
||||
UserStaticRules::atLeastRole($authUser, $user->role);
|
||||
}
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ class UserPolicy
|
|||
public function duplicate(User $authUser, User $user): bool
|
||||
{
|
||||
return $authUser->getRouteKey() !== $user->getRouteKey() and
|
||||
UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and
|
||||
UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor) and
|
||||
UserStaticRules::atLeastRole($authUser, $user->role);
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ class UserPolicy
|
|||
public function changePublished(User $authUser, User $user): bool
|
||||
{
|
||||
return $authUser->getRouteKey() !== $user->getRouteKey() and
|
||||
UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and
|
||||
UserStaticRules::atLeastRole($authUser, RoleEnum::conceptor) and
|
||||
UserStaticRules::atLeastRole($authUser, $user->role);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use App\Enums\Users\RoleEnum;
|
|||
use App\Lib\Helper;
|
||||
use App\Models\Service;
|
||||
use App\Models\User;
|
||||
use App\Policies\StatisticPolicy;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
|
|
@ -35,6 +36,10 @@ class AuthServiceProvider extends ServiceProvider
|
|||
return $user->role === RoleEnum::conceptor;
|
||||
});
|
||||
|
||||
Gate::define('viewStatsByBrand', [StatisticPolicy::class, 'viewStatsByBrand']);
|
||||
Gate::define('viewByQuestion', [StatisticPolicy::class, 'viewByQuestion']);
|
||||
Gate::define('answersByDays', [StatisticPolicy::class, 'answersByDays']);
|
||||
|
||||
Auth::viaRequest('api-hmac', function (Request $request) {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Events\ClaimModelChanged;
|
||||
use App\Listeners\AddClaimMessageSystem;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
|
|
@ -20,9 +22,8 @@ class EventServiceProvider extends ServiceProvider
|
|||
* @var array<class-string, array<int, class-string>>
|
||||
*/
|
||||
protected $listen = [
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
Registered::class => [SendEmailVerificationNotification::class],
|
||||
ClaimModelChanged::class => [AddClaimMessageSystem::class],
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
namespace App\Traits\Models;
|
||||
|
||||
use App\Enums\InputType;
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
use Uwil\LaravelCommon\Helpers\FileHelper;
|
||||
|
||||
trait MiniCrudModel
|
||||
{
|
||||
|
|
@ -38,7 +38,7 @@ trait MiniCrudModel
|
|||
switch ($input['inputType']) {
|
||||
case InputType::text->value:
|
||||
$input['text'] = clean($input['text']);
|
||||
$input['text'] = FileStorageHelper::storeModelFilesFromHtml($this, $input['text']);
|
||||
$input['text'] = FileHelper::storeModelFilesFromHtml($this, $input['text']);
|
||||
break;
|
||||
} //end switch
|
||||
} //end foreach
|
||||
|
|
@ -67,7 +67,7 @@ trait MiniCrudModel
|
|||
switch ($input['inputType']) {
|
||||
case InputType::text->value:
|
||||
$original = ToolboxHelper::getOriginal($this, 'data');
|
||||
FileStorageHelper::removeOldModelFilesFromHtml(
|
||||
FileHelper::removeOldModelFilesFromHtml(
|
||||
$input['text'],
|
||||
$original[$index]['text'] ?? ''
|
||||
);
|
||||
|
|
@ -87,7 +87,7 @@ trait MiniCrudModel
|
|||
foreach ($this->data as $input) {
|
||||
switch ($input['inputType']) {
|
||||
case InputType::text->value:
|
||||
FileStorageHelper::removeModelFilesOfHtml($input['text']);
|
||||
FileHelper::removeModelFilesOfHtml($input['text']);
|
||||
break;
|
||||
} //end switch
|
||||
} //end foreach
|
||||
|
|
@ -151,7 +151,7 @@ trait MiniCrudModel
|
|||
$data[$o]['value'] = \preg_replace(
|
||||
'/^\/|^/',
|
||||
'',
|
||||
FileStorageHelper::storeFile($this, $input['value'], true)
|
||||
FileHelper::storeFile($this, $input['value'], true)
|
||||
);
|
||||
break;
|
||||
case InputType::selectEnum->value:
|
||||
|
|
|
|||
|
|
@ -38,10 +38,10 @@
|
|||
"league/csv": "^9.7",
|
||||
"mews/purifier": "^3.4",
|
||||
"propaganistas/laravel-phone": "^5.0",
|
||||
"rennokki/laravel-eloquent-query-cache": "^3.5",
|
||||
"sentry/sentry-laravel": "^4.10",
|
||||
"uwil/admin-secure-laravel": "^3.0",
|
||||
"uwil/k8s-laravel": "^1.4"
|
||||
"uwil/k8s-laravel": "^1.4",
|
||||
"uwil/laravel-common": "^3.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"brianium/paratest": "^7.2",
|
||||
|
|
|
|||
338
composer.lock
generated
338
composer.lock
generated
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "3343f5ab073be3ad2e381f796d2dbb59",
|
||||
"content-hash": "ee8bdd66e3ddef5e410f2b2a7d852c2b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "24slides/laravel-saml2",
|
||||
|
|
@ -1964,6 +1964,150 @@
|
|||
],
|
||||
"time": "2023-12-03T19:50:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "intervention/gif",
|
||||
"version": "4.2.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Intervention/gif.git",
|
||||
"reference": "5999eac6a39aa760fb803bc809e8909ee67b451a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Intervention/gif/zipball/5999eac6a39aa760fb803bc809e8909ee67b451a",
|
||||
"reference": "5999eac6a39aa760fb803bc809e8909ee67b451a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^8.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpstan/phpstan": "^2.1",
|
||||
"phpunit/phpunit": "^10.0 || ^11.0 || ^12.0",
|
||||
"slevomat/coding-standard": "~8.0",
|
||||
"squizlabs/php_codesniffer": "^3.8"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Intervention\\Gif\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Oliver Vogel",
|
||||
"email": "oliver@intervention.io",
|
||||
"homepage": "https://intervention.io/"
|
||||
}
|
||||
],
|
||||
"description": "Native PHP GIF Encoder/Decoder",
|
||||
"homepage": "https://github.com/intervention/gif",
|
||||
"keywords": [
|
||||
"animation",
|
||||
"gd",
|
||||
"gif",
|
||||
"image"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Intervention/gif/issues",
|
||||
"source": "https://github.com/Intervention/gif/tree/4.2.2"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://paypal.me/interventionio",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/Intervention",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://ko-fi.com/interventionphp",
|
||||
"type": "ko_fi"
|
||||
}
|
||||
],
|
||||
"time": "2025-03-29T07:46:21+00:00"
|
||||
},
|
||||
{
|
||||
"name": "intervention/image",
|
||||
"version": "3.11.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Intervention/image.git",
|
||||
"reference": "d0f097b8a3fa8fb758efc9440b513aa3833cda17"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Intervention/image/zipball/d0f097b8a3fa8fb758efc9440b513aa3833cda17",
|
||||
"reference": "d0f097b8a3fa8fb758efc9440b513aa3833cda17",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-mbstring": "*",
|
||||
"intervention/gif": "^4.2",
|
||||
"php": "^8.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^1.6",
|
||||
"phpstan/phpstan": "^2.1",
|
||||
"phpunit/phpunit": "^10.0 || ^11.0 || ^12.0",
|
||||
"slevomat/coding-standard": "~8.0",
|
||||
"squizlabs/php_codesniffer": "^3.8"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-exif": "Recommended to be able to read EXIF data properly."
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Intervention\\Image\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Oliver Vogel",
|
||||
"email": "oliver@intervention.io",
|
||||
"homepage": "https://intervention.io/"
|
||||
}
|
||||
],
|
||||
"description": "PHP image manipulation",
|
||||
"homepage": "https://image.intervention.io/",
|
||||
"keywords": [
|
||||
"gd",
|
||||
"image",
|
||||
"imagick",
|
||||
"resize",
|
||||
"thumbnail",
|
||||
"watermark"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Intervention/image/issues",
|
||||
"source": "https://github.com/Intervention/image/tree/3.11.3"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://paypal.me/interventionio",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/Intervention",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://ko-fi.com/interventionphp",
|
||||
"type": "ko_fi"
|
||||
}
|
||||
],
|
||||
"time": "2025-05-22T17:26:23+00:00"
|
||||
},
|
||||
{
|
||||
"name": "jean85/pretty-package-versions",
|
||||
"version": "2.1.0",
|
||||
|
|
@ -2023,6 +2167,68 @@
|
|||
},
|
||||
"time": "2024-11-18T16:19:46+00:00"
|
||||
},
|
||||
{
|
||||
"name": "kwaadpepper/image-resizer",
|
||||
"version": "3.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Kwaadpepper/image-resizer.git",
|
||||
"reference": "e0747fddc4e31ce57bda9db735060e279ae01780"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Kwaadpepper/image-resizer/zipball/e0747fddc4e31ce57bda9db735060e279ae01780",
|
||||
"reference": "e0747fddc4e31ce57bda9db735060e279ae01780",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/support": "~11|~12",
|
||||
"intervention/image": "^3.6",
|
||||
"laravel/framework": "~11|~12",
|
||||
"php": "^8.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"larastan/larastan": "^2.0",
|
||||
"orchestra/testbench": "^9.0",
|
||||
"slevomat/coding-standard": "^8.11"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Kwaadpepper\\ImageResizer\\ImageResizerServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Kwaadpepper\\ImageResizer\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jérémy Munsch",
|
||||
"email": "github@jeremydev.ovh",
|
||||
"homepage": "https://jeremydev.ovh"
|
||||
}
|
||||
],
|
||||
"description": "Resize images on the fly and cache them",
|
||||
"homepage": "https://github.com/kwaadpepper/image-resizer",
|
||||
"keywords": [
|
||||
"images",
|
||||
"laravel",
|
||||
"resize"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Kwaadpepper/image-resizer/issues",
|
||||
"source": "https://github.com/Kwaadpepper/image-resizer/tree/3.1.0"
|
||||
},
|
||||
"time": "2025-03-02T07:22:50+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/framework",
|
||||
"version": "v11.37.0",
|
||||
|
|
@ -4867,72 +5073,6 @@
|
|||
],
|
||||
"time": "2024-04-27T21:32:50+00:00"
|
||||
},
|
||||
{
|
||||
"name": "rennokki/laravel-eloquent-query-cache",
|
||||
"version": "3.5.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/renoki-co/laravel-eloquent-query-cache.git",
|
||||
"reference": "094d1d165d219a1c0bcdc9cf966a72d78f63c46e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/renoki-co/laravel-eloquent-query-cache/zipball/094d1d165d219a1c0bcdc9cf966a72d78f63c46e",
|
||||
"reference": "094d1d165d219a1c0bcdc9cf966a72d78f63c46e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/database": "^10.5|^11.33",
|
||||
"illuminate/support": "^10.5|^11.33"
|
||||
},
|
||||
"require-dev": {
|
||||
"chelout/laravel-relationship-events": "^1.5|^2.0|^3.0",
|
||||
"laravel/legacy-factories": "^1.4",
|
||||
"livewire/livewire": "dev-main",
|
||||
"mockery/mockery": "^1.6",
|
||||
"orchestra/testbench": "^8.1.1|^9",
|
||||
"phpunit/phpunit": "^9.5.25|^10|^11"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Rennokki\\QueryCache\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Alex Renoki",
|
||||
"email": "alex@renoki.org",
|
||||
"homepage": "https://github.com/rennokki",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Adding cache on your Laravel Eloquent queries' results is now a breeze.",
|
||||
"homepage": "https://github.com/renoki-co/laravel-eloquent-query-cache",
|
||||
"keywords": [
|
||||
"caching",
|
||||
"eloquent",
|
||||
"laravel",
|
||||
"query",
|
||||
"remember",
|
||||
"sql"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/renoki-co/laravel-eloquent-query-cache/issues",
|
||||
"source": "https://github.com/renoki-co/laravel-eloquent-query-cache/tree/3.5.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/rennokki",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2024-11-30T17:53:54+00:00"
|
||||
},
|
||||
{
|
||||
"name": "robrichards/xmlseclibs",
|
||||
"version": "3.1.3",
|
||||
|
|
@ -7717,6 +7857,70 @@
|
|||
],
|
||||
"description": "Laravel requirements for k8s"
|
||||
},
|
||||
{
|
||||
"name": "uwil/laravel-common",
|
||||
"version": "3.4.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "git@lab.s-web.fr:ldc-web/projets/laravel-common.git",
|
||||
"reference": "e4d69be567729f0e32379b4ed1ed8cd0dc3746df"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://lab.s-web.fr/api/v4/projects/215/packages/composer/archives/uwil/laravel-common.zip?sha=e4d69be567729f0e32379b4ed1ed8cd0dc3746df",
|
||||
"reference": "e4d69be567729f0e32379b4ed1ed8cd0dc3746df",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/support": "~11|~12",
|
||||
"kwaadpepper/image-resizer": "^3.0",
|
||||
"laravel/framework": "~11|~12",
|
||||
"mews/purifier": "^3.4",
|
||||
"php": "~8.3",
|
||||
"sentry/sentry-laravel": "^4.10"
|
||||
},
|
||||
"require-dev": {
|
||||
"larastan/larastan": "^2.9",
|
||||
"orchestra/testbench": "^9.0",
|
||||
"phpunit/php-code-coverage": "^11.0",
|
||||
"phpunit/phpunit": "^11.0",
|
||||
"slevomat/coding-standard": "^8.3",
|
||||
"squizlabs/php_codesniffer": "^3.7"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Uwil\\LaravelCommon\\CommonServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/Helpers/methods.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Uwil\\LaravelCommon\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Uwil\\LaravelCommon\\Tests\\": "tests"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": [
|
||||
"vendor/bin/phpunit"
|
||||
],
|
||||
"post-autoload-dump": [
|
||||
"@php ./vendor/bin/testbench package:discover --ansi"
|
||||
]
|
||||
},
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"description": "UWIL Laravel common utils"
|
||||
},
|
||||
{
|
||||
"name": "vlucas/phpdotenv",
|
||||
"version": "v5.6.1",
|
||||
|
|
|
|||
2
database/.gitignore
vendored
2
database/.gitignore
vendored
|
|
@ -1,2 +0,0 @@
|
|||
*.sqlite
|
||||
*.sqlite-journal
|
||||
|
|
@ -19,7 +19,7 @@ class AnswerFactory extends Factory
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'answer' => $this->faker->realText(20),
|
||||
|
|
|
|||
|
|
@ -19,10 +19,13 @@ class BrandFactory extends Factory
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->company,
|
||||
'name' => $this->faker->company,
|
||||
'url' => $this->faker->url,
|
||||
'url_claim' => $this->faker->url,
|
||||
'domain' => $this->faker->domainName,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
48
database/factories/ClaimFactory.php
Normal file
48
database/factories/ClaimFactory.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\Claims\ClaimResponseType;
|
||||
use App\Enums\Claims\ClaimStatus;
|
||||
use App\Enums\Claims\ClaimType;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Claim;
|
||||
use App\Models\ClaimSubject;
|
||||
use App\Models\Customer;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ClaimFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Claim::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'first_name' => $this->faker->firstName(),
|
||||
'last_name' => $this->faker->lastName(),
|
||||
'email' => $this->faker->email(),
|
||||
'address' => $this->faker->optional()->address(),
|
||||
'city' => $this->faker->optional()->city(),
|
||||
'postcode' => $this->faker->optional()->postcode(),
|
||||
'message' => $this->faker->sentence(10),
|
||||
'response_type' => ClaimResponseType::none,
|
||||
'type' => collect(ClaimType::toArray())->random()->value,
|
||||
'status' => collect(ClaimStatus::toArray())->random()->value,
|
||||
'brand_id' => $this->faker->randomElement(Brand::query()->get()->modelKeys()),
|
||||
'subject_id' => $this->faker->randomElement(ClaimSubject::query()->get()->modelKeys()),
|
||||
'customer_id' => $this->faker->boolean(50)
|
||||
? $this->faker->randomElement(Customer::query()->get()->modelKeys())
|
||||
: null,
|
||||
];
|
||||
}
|
||||
}
|
||||
31
database/factories/ClaimMailTemplateFactory.php
Normal file
31
database/factories/ClaimMailTemplateFactory.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Brand;
|
||||
use App\Models\ClaimMailTemplate;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ClaimMailTemplateFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = ClaimMailTemplate::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'label' => $this->faker->word(),
|
||||
'content' => $this->faker->sentence(10),
|
||||
'brand_id' => $this->faker->randomElement(Brand::query()->get()->modelKeys()),
|
||||
];
|
||||
}
|
||||
}
|
||||
36
database/factories/ClaimMessageFactory.php
Normal file
36
database/factories/ClaimMessageFactory.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\Claims\ClaimMessageType;
|
||||
use App\Models\Claim;
|
||||
use App\Models\ClaimMessage;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ClaimMessageFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = ClaimMessage::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'content' => $this->faker->sentence(10),
|
||||
'type' => collect(ClaimMessageType::toArray())->random()->value,
|
||||
'claim_id' => $this->faker->randomElement(Claim::query()->get()->modelKeys()),
|
||||
'user_id' => $this->faker->boolean(50)
|
||||
? $this->faker->randomElement(User::query()->get()->modelKeys())
|
||||
: null,
|
||||
];
|
||||
}
|
||||
}
|
||||
30
database/factories/ClaimSubjectFactory.php
Normal file
30
database/factories/ClaimSubjectFactory.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Brand;
|
||||
use App\Models\ClaimSubject;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ClaimSubjectFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = ClaimSubject::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'label' => $this->faker->word(),
|
||||
'brand_id' => $this->faker->randomElement(Brand::query()->get()->modelKeys()),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ class CustomerFactory extends Factory
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'email' => preg_replace(
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class CustomerInfoFactory extends Factory
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
public function definition(): array
|
||||
{
|
||||
$faker = \Faker\Factory::create('fr_FR');
|
||||
$faker->addProvider(new \Faker\Provider\fr_FR\Address($faker));
|
||||
|
|
@ -36,17 +36,17 @@ class CustomerInfoFactory extends Factory
|
|||
$phone = '0388982532';
|
||||
}
|
||||
return [
|
||||
'firstname' => $faker->firstName,
|
||||
'lastname' => $faker->lastName,
|
||||
'firstname' => $faker->firstName,
|
||||
'lastname' => $faker->lastName,
|
||||
'birth_date' => $faker->dateTimeBetween('-60 years', '-18 years'),
|
||||
'address' => $faker->address,
|
||||
'address2' => '',
|
||||
'phone' => $phone,
|
||||
'country' => $country->value,
|
||||
'city' => $faker->city,
|
||||
'postcode' => $faker->postcode,
|
||||
'opt_in' => $faker->boolean,
|
||||
'hashcode' => $faker->sha1
|
||||
'address' => $faker->address,
|
||||
'address2' => '',
|
||||
'phone' => $phone,
|
||||
'country' => $country->value,
|
||||
'city' => $faker->city,
|
||||
'postcode' => $faker->postcode,
|
||||
'opt_in' => $faker->boolean,
|
||||
'hashcode' => $faker->sha1
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class CustomerLoginFactory extends Factory
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
public function definition(): array
|
||||
{
|
||||
$bool = $this->faker->boolean;
|
||||
// * Force first to be active.
|
||||
|
|
@ -36,9 +36,9 @@ class CustomerLoginFactory extends Factory
|
|||
$bool = false;
|
||||
}
|
||||
return [
|
||||
'password' => 'testPassword',
|
||||
'password' => 'testPassword',
|
||||
'last_connection' => Carbon::now(),
|
||||
'status' => $bool
|
||||
'status' => $bool
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class QuestionFactory extends Factory
|
|||
{
|
||||
return [
|
||||
'question' => $this->faker->realText(40),
|
||||
'type' => collect(QuestionType::toArray())->random()->value,
|
||||
'type' => collect(QuestionType::toArray())->random()->value,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class ServiceFactory extends Factory
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->lexify('?????????')
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class SingleOptinFactory extends Factory
|
|||
return [
|
||||
'hashcode' => Str::uuid(),
|
||||
'email' => $this->faker->email(),
|
||||
'brand_id' => $this->faker->randomElement(Brand::pluck('id')),
|
||||
'brand_id' => $this->faker->randomElement(Brand::query()->get()->modelKeys()),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,31 +13,18 @@ class UserFactory extends Factory
|
|||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition()
|
||||
public function definition(): array
|
||||
{
|
||||
$published = $this->faker->boolean(75);
|
||||
return [
|
||||
'first_name' => fake()->firstname(),
|
||||
'last_name' => fake()->lastname(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
|
||||
'first_name' => $this->faker->firstname(),
|
||||
'last_name' => $this->faker->lastname(),
|
||||
'email' => $this->faker->unique()->safeEmail(),
|
||||
'remember_token' => Str::random(10),
|
||||
'role' => \collect(RoleEnum::toArray())->random()->value,
|
||||
'published' => $published,
|
||||
'published_at' => ($published) ? now() : null,
|
||||
'last_connection' => ($published) ? now() : null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn() => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
BIN
database/factories/assets/brands/default-logo-550x550.jpg
Normal file
BIN
database/factories/assets/brands/default-logo-550x550.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.9 KiB |
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('brands', function (Blueprint $table) {
|
||||
$table->id()->comment('Brand id.')->change();
|
||||
$table->string('name')->comment('Brand name.')->change();
|
||||
$table->string('logo')->comment('Brand logo.')->after('name');
|
||||
$table->string('url')->comment('Brand url link.')->after('logo');
|
||||
$table->string('url_claim')->comment('Brand associative url claim.')->after('url');
|
||||
$table->string('domain')->comment('Brand domain.')->after('url_claim');
|
||||
$table->timestamp('created_at')->nullable()->comment('Brand created date.')->change();
|
||||
$table->timestamp('updated_at')->nullable()->comment('Brand updated date.')->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('brands', function (Blueprint $table) {
|
||||
$table->id()->change();
|
||||
$table->string('name')->change();
|
||||
$table->dropColumn('logo');
|
||||
$table->dropColumn('url');
|
||||
$table->dropColumn('url_claim');
|
||||
$table->dropColumn('domain');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('brand_users', function (Blueprint $table) {
|
||||
$table->foreignId('brand_id')->comment('Brand associated.')->constrained('brands')
|
||||
->onUpdate('cascade')->onDelete('cascade');
|
||||
$table->foreignId('user_id')->comment('User associated.')->constrained('users')
|
||||
->onUpdate('cascade')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('brand_users');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('claim_mail_templates', function (Blueprint $table) {
|
||||
$table->id()->comment('Mail template id.');
|
||||
$table->string('label')->comment('Mail template label.');
|
||||
$table->text('content')->comment('Mail template content.');
|
||||
$table->foreignId('brand_id')->comment('Mail template associated Brand.')->constrained('brands')
|
||||
->onUpdate('cascade')->onDelete('cascade');
|
||||
$table->timestamp('created_at')->nullable()->comment('Mail template created date.');
|
||||
$table->timestamp('updated_at')->nullable()->comment('Mail template updated date.');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('claim_mail_templates');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('claim_subjects', function (Blueprint $table) {
|
||||
$table->id()->comment('Subject id.');
|
||||
$table->string('label')->comment('Subject label.');
|
||||
$table->foreignId('brand_id')->comment('Subject associated Brand.')->constrained('brands')
|
||||
->onUpdate('cascade')->onDelete('cascade');
|
||||
$table->timestamp('created_at')->nullable()->comment('Subject created date.');
|
||||
$table->timestamp('updated_at')->nullable()->comment('Subject updated date.');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('claim_subjects');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\Claims\ClaimResponseType;
|
||||
use App\Enums\Claims\ClaimStatus;
|
||||
use App\Enums\Claims\ClaimType;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('claims', function (Blueprint $table) {
|
||||
$table->id()->comment('Claim id.');
|
||||
$table->string('reference')->nullable()->default(null)->comment('Claim reference.');
|
||||
$table->string('first_name')->comment('Claimant\'s first name.');
|
||||
$table->string('last_name')->comment('Claimant\'s last name.');
|
||||
$table->string('email')->comment('Claimant\'s email.');
|
||||
$table->string('address')->nullable()->comment('Claimant\'s address.');
|
||||
$table->string('city')->nullable()->comment('Claimant\'s city.');
|
||||
$table->string('postcode')->nullable()->comment('Claimant\'s postcode.');
|
||||
$table->string('file')->nullable()->comment('Claimant\'s file.');
|
||||
$table->text('message')->comment('Claimant\'s message.');
|
||||
$table->unsignedTinyInteger('response_type')->default(ClaimResponseType::none)
|
||||
->comment('Claim response type (ClaimResponseType enum).');
|
||||
$table->unsignedTinyInteger('status')->default(ClaimStatus::untreated)
|
||||
->comment('Claim status (ClaimStatus enum).');
|
||||
$table->unsignedTinyInteger('type')->default(ClaimType::classic)
|
||||
->comment('Claim type (ClaimType enum).');
|
||||
$table->foreignId('brand_id')->comment('Claim associated Brand.')->constrained('brands')
|
||||
->onUpdate('cascade')->onDelete('cascade');
|
||||
$table->foreignId('subject_id')->comment('Claim associated Subject.')->constrained('claim_subjects')
|
||||
->onUpdate('cascade')->onDelete('cascade');
|
||||
$table->foreignId('customer_id')->nullable()->comment('Claim associated Customer.')
|
||||
->constrained('customers')->onUpdate('cascade')->onDelete('set null');
|
||||
$table->timestamp('created_at')->nullable()->comment('Claim created date.');
|
||||
$table->timestamp('updated_at')->nullable()->comment('Claim updated date.');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('claims');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('claim_messages', function (Blueprint $table) {
|
||||
$table->id()->comment('Message id.');
|
||||
$table->text('content')->comment('Message content.');
|
||||
$table->unsignedTinyInteger('type')->comment('Message type (MessageType enum).');
|
||||
$table->foreignId('claim_id')->comment('Message associated Claim.')->constrained('claims')
|
||||
->onUpdate('cascade')->onDelete('cascade');
|
||||
$table->foreignId('user_id')->nullable()->comment('Message associated User.')->constrained('users')
|
||||
->onUpdate('cascade')->onDelete('cascade');
|
||||
$table->timestamp('created_at')->nullable()->comment('Message created date.');
|
||||
$table->timestamp('updated_at')->nullable()->comment('Message updated date.');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('claim_messages');
|
||||
}
|
||||
};
|
||||
|
|
@ -16,7 +16,7 @@ return new class extends Migration
|
|||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('email_verified_at');
|
||||
$table->dropColumn('password');
|
||||
$table->date('last_connection')->nullable()->after('published_at');
|
||||
$table->timestamp('last_connection')->nullable()->after('published_at');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use App\Models\Brand;
|
|||
use App\Models\Question;
|
||||
use App\Models\Service;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Uwil\LaravelCommon\Helpers\FileHelper;
|
||||
|
||||
class BrandSeeder extends Seeder
|
||||
{
|
||||
|
|
@ -15,10 +16,17 @@ class BrandSeeder extends Seeder
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
public function run(): void
|
||||
{
|
||||
/** @var \App\Models\Brand $brand */
|
||||
Brand::factory(10)->create()->each(function ($brand) {
|
||||
Brand::factory(10)->make()->each(function ($brand) {
|
||||
$brand->logo = FileHelper::storeFile(
|
||||
$brand,
|
||||
new \SplFileInfo(
|
||||
\resource_path('../database/factories/assets/brands/default-logo-550x550.jpg')
|
||||
)
|
||||
);
|
||||
$brand->saveOrFail();
|
||||
Service::factory(1)->make()->each(
|
||||
/** @var \App\Models\Service $service*/
|
||||
function ($service) use ($brand) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class BrandStatSeeder extends Seeder
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
public function run(): void
|
||||
{
|
||||
BrandStat::truncate();
|
||||
// * On génère 1 an pour chaque marque.
|
||||
|
|
@ -36,13 +36,13 @@ class BrandStatSeeder extends Seeder
|
|||
$pOld = 1 - $pNew;
|
||||
|
||||
$brandStat = new BrandStat([
|
||||
'active' => \floor($total * $pActive),
|
||||
'inactive' => \ceil($total * $pInactive),
|
||||
'old_accounts' => \ceil($total * $pOld),
|
||||
'new_accounts' => \floor($total * $pNew),
|
||||
'active' => \floor($total * $pActive),
|
||||
'inactive' => \ceil($total * $pInactive),
|
||||
'old_accounts' => \ceil($total * $pOld),
|
||||
'new_accounts' => \floor($total * $pNew),
|
||||
'total_accounts' => $total,
|
||||
// 15% optin
|
||||
'total_opt_in' => ceil($total * 0.15)
|
||||
'total_opt_in' => ceil($total * 0.15)
|
||||
]);
|
||||
$brandStat->brand()->associate($brand);
|
||||
$brandStat->created_at = $startDay;
|
||||
|
|
|
|||
19
database/seeders/ClaimMailTemplateSeeder.php
Normal file
19
database/seeders/ClaimMailTemplateSeeder.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\ClaimMailTemplate;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ClaimMailTemplateSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
ClaimMailTemplate::factory(20)->create();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue