Migrate backend to Porto architecture and fix minor bugs
- Fully transitioned the backend to the Porto architectural pattern - Improved code organization and maintainability - Fixed minor bugs and inconsistencies
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Data\Rules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UniqueJsonField implements Rule
|
||||
{
|
||||
protected int $formId;
|
||||
protected string $fieldName;
|
||||
|
||||
public function __construct($formId, $fieldName)
|
||||
{
|
||||
$this->formId = $formId;
|
||||
$this->fieldName = $fieldName;
|
||||
}
|
||||
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
// Получаем все записи для данного custom_form_id
|
||||
$responses = DB::table('custom_form_responses')
|
||||
->where('custom_form_id', $this->formId)
|
||||
->pluck('answers');
|
||||
|
||||
// Проверяем, есть ли значение в JSON
|
||||
foreach ($responses as $response) {
|
||||
$answers = json_decode($response, true);
|
||||
if (isset($answers[$this->fieldName]) && $answers[$this->fieldName] === $value) {
|
||||
return false; // Значение не уникально
|
||||
}
|
||||
}
|
||||
|
||||
return true; // Значение уникально
|
||||
}
|
||||
|
||||
public function message()
|
||||
{
|
||||
return 'Поле должно быть уникальным';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Enums;
|
||||
|
||||
use Filament\Support\Contracts\HasLabel;
|
||||
use Filament\Support\Contracts\HasColor;
|
||||
|
||||
enum CustomFormStatus: string implements HasLabel, HasColor
|
||||
{
|
||||
|
||||
case PUBLISHED = 'published';
|
||||
case HIDDEN = 'hidden';
|
||||
|
||||
public function getLabel(): ?string
|
||||
{
|
||||
return match ($this) {
|
||||
self::PUBLISHED => 'Опубликовано',
|
||||
self::HIDDEN => 'Скрыто',
|
||||
};
|
||||
}
|
||||
|
||||
public function getColor(): string|array|null
|
||||
{
|
||||
return match ($this) {
|
||||
self::PUBLISHED => 'success',
|
||||
self::HIDDEN => 'gray',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Loaders;
|
||||
|
||||
class AliasesLoader
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $aliases = [];
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Loaders;
|
||||
|
||||
class MiddlewareLoader
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $middleware = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $middlewareGroups = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $routeMiddleware = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $middlewarePriority = [];
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Loaders;
|
||||
|
||||
class ProvidersLoader
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $providers = [];
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Mails;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CustomFormResponseMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public array $settings;
|
||||
public array $answers;
|
||||
public array $columns;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $settings, array $answers, array $columns)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
$this->answers = $answers;
|
||||
$this->columns = $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: $this->settings['topic'], // Используем тему из настроек
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.custom-form-response', // Укажите путь к вашему шаблону
|
||||
with: [
|
||||
'data' => $this->settings['data'],
|
||||
'answers' => $this->answers,
|
||||
'columns' => $this->columns,
|
||||
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ContactWidget extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = false;
|
||||
|
||||
protected $casts = [
|
||||
'content' => 'array',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Models;
|
||||
|
||||
use App\Containers\Widget\Enums\CustomFormStatus;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CustomForm extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = false;
|
||||
|
||||
protected $casts = [
|
||||
'columns' => 'array',
|
||||
'status' => CustomFormStatus::class,
|
||||
'mail_settings' => 'array',
|
||||
'settings' => 'array',
|
||||
];
|
||||
|
||||
public function responses()
|
||||
{
|
||||
return $this->hasMany(CustomFormResponse::class, 'custom_form_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CustomFormResponse extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = false;
|
||||
|
||||
protected $casts = [
|
||||
'answers' => 'array'
|
||||
];
|
||||
|
||||
public function form()
|
||||
{
|
||||
return $this->belongsTo(CustomForm::class, 'custom_form_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PageReferenceList extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = false;
|
||||
|
||||
protected $casts = [
|
||||
'content' => 'array',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Slide extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = false;
|
||||
|
||||
protected $casts = [
|
||||
'settings' => 'array',
|
||||
'image' => 'array',
|
||||
];
|
||||
|
||||
public function slider(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Slider::class);
|
||||
}
|
||||
|
||||
public function slidable()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Slider extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = false;
|
||||
|
||||
|
||||
public function slides(): HasMany
|
||||
{
|
||||
return $this->hasMany(Slide::class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Policies;
|
||||
|
||||
use App\Containers\User\Models\User;
|
||||
use App\Containers\Widget\Models\ContactWidget;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class ContactWidgetPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->can('view_any_contact::widget');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, ContactWidget $contactWidget): bool
|
||||
{
|
||||
return $user->can('view_contact::widget');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $user->can('create_contact::widget');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, ContactWidget $contactWidget): bool
|
||||
{
|
||||
return $user->can('update_contact::widget');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, ContactWidget $contactWidget): bool
|
||||
{
|
||||
return $user->can('delete_contact::widget');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can bulk delete.
|
||||
*/
|
||||
public function deleteAny(User $user): bool
|
||||
{
|
||||
return $user->can('delete_any_contact::widget');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete.
|
||||
*/
|
||||
public function forceDelete(User $user, ContactWidget $contactWidget): bool
|
||||
{
|
||||
return $user->can('force_delete_contact::widget');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently bulk delete.
|
||||
*/
|
||||
public function forceDeleteAny(User $user): bool
|
||||
{
|
||||
return $user->can('force_delete_any_contact::widget');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore.
|
||||
*/
|
||||
public function restore(User $user, ContactWidget $contactWidget): bool
|
||||
{
|
||||
return $user->can('restore_contact::widget');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can bulk restore.
|
||||
*/
|
||||
public function restoreAny(User $user): bool
|
||||
{
|
||||
return $user->can('restore_any_contact::widget');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can replicate.
|
||||
*/
|
||||
public function replicate(User $user, ContactWidget $contactWidget): bool
|
||||
{
|
||||
return $user->can('replicate_contact::widget');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can reorder.
|
||||
*/
|
||||
public function reorder(User $user): bool
|
||||
{
|
||||
return $user->can('reorder_contact::widget');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Policies;
|
||||
|
||||
use App\Containers\User\Models\User;
|
||||
use App\Containers\Widget\Models\CustomForm;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class CustomFormPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->can('view_any_custom::form');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, CustomForm $customForm): bool
|
||||
{
|
||||
return $user->can('view_custom::form');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $user->can('create_custom::form');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, CustomForm $customForm): bool
|
||||
{
|
||||
return $user->can('update_custom::form');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, CustomForm $customForm): bool
|
||||
{
|
||||
return $user->can('delete_custom::form');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can bulk delete.
|
||||
*/
|
||||
public function deleteAny(User $user): bool
|
||||
{
|
||||
return $user->can('delete_any_custom::form');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete.
|
||||
*/
|
||||
public function forceDelete(User $user, CustomForm $customForm): bool
|
||||
{
|
||||
return $user->can('force_delete_custom::form');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently bulk delete.
|
||||
*/
|
||||
public function forceDeleteAny(User $user): bool
|
||||
{
|
||||
return $user->can('force_delete_any_custom::form');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore.
|
||||
*/
|
||||
public function restore(User $user, CustomForm $customForm): bool
|
||||
{
|
||||
return $user->can('restore_custom::form');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can bulk restore.
|
||||
*/
|
||||
public function restoreAny(User $user): bool
|
||||
{
|
||||
return $user->can('restore_any_custom::form');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can replicate.
|
||||
*/
|
||||
public function replicate(User $user, CustomForm $customForm): bool
|
||||
{
|
||||
return $user->can('replicate_custom::form');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can reorder.
|
||||
*/
|
||||
public function reorder(User $user): bool
|
||||
{
|
||||
return $user->can('reorder_custom::form');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Policies;
|
||||
|
||||
use App\Containers\User\Models\User;
|
||||
use App\Containers\Widget\Models\CustomFormResponse;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class CustomFormResponsePolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->can('view_any_custom::form::response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, CustomFormResponse $customFormResponse): bool
|
||||
{
|
||||
return $user->can('view_custom::form::response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $user->can('create_custom::form::response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, CustomFormResponse $customFormResponse): bool
|
||||
{
|
||||
return $user->can('update_custom::form::response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, CustomFormResponse $customFormResponse): bool
|
||||
{
|
||||
return $user->can('delete_custom::form::response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can bulk delete.
|
||||
*/
|
||||
public function deleteAny(User $user): bool
|
||||
{
|
||||
return $user->can('delete_any_custom::form::response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete.
|
||||
*/
|
||||
public function forceDelete(User $user, CustomFormResponse $customFormResponse): bool
|
||||
{
|
||||
return $user->can('force_delete_custom::form::response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently bulk delete.
|
||||
*/
|
||||
public function forceDeleteAny(User $user): bool
|
||||
{
|
||||
return $user->can('force_delete_any_custom::form::response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore.
|
||||
*/
|
||||
public function restore(User $user, CustomFormResponse $customFormResponse): bool
|
||||
{
|
||||
return $user->can('restore_custom::form::response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can bulk restore.
|
||||
*/
|
||||
public function restoreAny(User $user): bool
|
||||
{
|
||||
return $user->can('restore_any_custom::form::response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can replicate.
|
||||
*/
|
||||
public function replicate(User $user, CustomFormResponse $customFormResponse): bool
|
||||
{
|
||||
return $user->can('replicate_custom::form::response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can reorder.
|
||||
*/
|
||||
public function reorder(User $user): bool
|
||||
{
|
||||
return $user->can('reorder_custom::form::response');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Policies;
|
||||
|
||||
use App\Containers\User\Models\User;
|
||||
use App\Containers\Widget\Models\PageReferenceList;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class PageReferenceListPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->can('view_any_page::reference::list');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, PageReferenceList $pageReferenceList): bool
|
||||
{
|
||||
return $user->can('view_page::reference::list');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $user->can('create_page::reference::list');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, PageReferenceList $pageReferenceList): bool
|
||||
{
|
||||
return $user->can('update_page::reference::list');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, PageReferenceList $pageReferenceList): bool
|
||||
{
|
||||
return $user->can('delete_page::reference::list');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can bulk delete.
|
||||
*/
|
||||
public function deleteAny(User $user): bool
|
||||
{
|
||||
return $user->can('delete_any_page::reference::list');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete.
|
||||
*/
|
||||
public function forceDelete(User $user, PageReferenceList $pageReferenceList): bool
|
||||
{
|
||||
return $user->can('force_delete_page::reference::list');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently bulk delete.
|
||||
*/
|
||||
public function forceDeleteAny(User $user): bool
|
||||
{
|
||||
return $user->can('force_delete_any_page::reference::list');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore.
|
||||
*/
|
||||
public function restore(User $user, PageReferenceList $pageReferenceList): bool
|
||||
{
|
||||
return $user->can('restore_page::reference::list');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can bulk restore.
|
||||
*/
|
||||
public function restoreAny(User $user): bool
|
||||
{
|
||||
return $user->can('restore_any_page::reference::list');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can replicate.
|
||||
*/
|
||||
public function replicate(User $user, PageReferenceList $pageReferenceList): bool
|
||||
{
|
||||
return $user->can('replicate_page::reference::list');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can reorder.
|
||||
*/
|
||||
public function reorder(User $user): bool
|
||||
{
|
||||
return $user->can('reorder_page::reference::list');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Policies;
|
||||
|
||||
use App\Containers\User\Models\User;
|
||||
use App\Containers\Widget\Models\Slide;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class SlidePolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->can('view_any_slide');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, Slide $slide): bool
|
||||
{
|
||||
return $user->can('view_slide');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $user->can('create_slide');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, Slide $slide): bool
|
||||
{
|
||||
return $user->can('update_slide');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, Slide $slide): bool
|
||||
{
|
||||
return $user->can('delete_slide');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can bulk delete.
|
||||
*/
|
||||
public function deleteAny(User $user): bool
|
||||
{
|
||||
return $user->can('delete_any_slide');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete.
|
||||
*/
|
||||
public function forceDelete(User $user, Slide $slide): bool
|
||||
{
|
||||
return $user->can('force_delete_slide');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently bulk delete.
|
||||
*/
|
||||
public function forceDeleteAny(User $user): bool
|
||||
{
|
||||
return $user->can('force_delete_any_slide');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore.
|
||||
*/
|
||||
public function restore(User $user, Slide $slide): bool
|
||||
{
|
||||
return $user->can('restore_slide');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can bulk restore.
|
||||
*/
|
||||
public function restoreAny(User $user): bool
|
||||
{
|
||||
return $user->can('restore_any_slide');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can replicate.
|
||||
*/
|
||||
public function replicate(User $user, Slide $slide): bool
|
||||
{
|
||||
return $user->can('replicate_slide');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can reorder.
|
||||
*/
|
||||
public function reorder(User $user): bool
|
||||
{
|
||||
return $user->can('reorder_slide');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Policies;
|
||||
|
||||
use App\Containers\User\Models\User;
|
||||
use App\Containers\Widget\Models\Slider;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class SliderPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->can('view_any_slider');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, Slider $slider): bool
|
||||
{
|
||||
return $user->can('view_slider');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $user->can('create_slider');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, Slider $slider): bool
|
||||
{
|
||||
return $user->can('update_slider');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, Slider $slider): bool
|
||||
{
|
||||
return $user->can('delete_slider');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can bulk delete.
|
||||
*/
|
||||
public function deleteAny(User $user): bool
|
||||
{
|
||||
return $user->can('delete_any_slider');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete.
|
||||
*/
|
||||
public function forceDelete(User $user, Slider $slider): bool
|
||||
{
|
||||
return $user->can('force_delete_slider');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently bulk delete.
|
||||
*/
|
||||
public function forceDeleteAny(User $user): bool
|
||||
{
|
||||
return $user->can('force_delete_any_slider');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore.
|
||||
*/
|
||||
public function restore(User $user, Slider $slider): bool
|
||||
{
|
||||
return $user->can('restore_slider');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can bulk restore.
|
||||
*/
|
||||
public function restoreAny(User $user): bool
|
||||
{
|
||||
return $user->can('restore_any_slider');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can replicate.
|
||||
*/
|
||||
public function replicate(User $user, Slider $slider): bool
|
||||
{
|
||||
return $user->can('replicate_slider');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can reorder.
|
||||
*/
|
||||
public function reorder(User $user): bool
|
||||
{
|
||||
return $user->can('reorder_slider');
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\UI\API\Controllers;
|
||||
|
||||
use App\Containers\AdditionalEducation\Models\AdditionalEducation;
|
||||
use App\Containers\Search\UI\API\Transformers\AdditionalEducationSearchResource;
|
||||
use App\Ship\Controllers\Controller;
|
||||
use App\Ship\Enums\CacheKeys;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ClientWidgetAdditionalEducationalProgramController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return Cache::remember(
|
||||
CacheKeys::ADDITIONAL_EDUCATIONAL_PROGRAMS_PREFIX->value . 'search_list',
|
||||
now()->addDay(), // Кешируем на 1 день
|
||||
function () {
|
||||
return AdditionalEducationSearchResource::collection(
|
||||
AdditionalEducation::query()
|
||||
->where('is_active', true)
|
||||
->orderBy('title', 'desc')
|
||||
->get()
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\UI\API\Controllers;
|
||||
|
||||
use App\Containers\Widget\Models\ContactWidget;
|
||||
use App\Containers\Widget\UI\API\Transformers\ContactWidgetResource;
|
||||
use App\Ship\Controllers\Controller;
|
||||
use App\Ship\Enums\CacheKeys;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ClientWidgetContactController extends Controller
|
||||
{
|
||||
public function show(string $slug)
|
||||
{
|
||||
return Cache::remember(
|
||||
CacheKeys::CONTACT_WIDGET_PREFIX->value . $slug,
|
||||
now()->addHours(12), // Кешируем на 12 часов
|
||||
function () use ($slug) {
|
||||
return new ContactWidgetResource(
|
||||
ContactWidget::query()
|
||||
->where('slug', $slug)
|
||||
->firstOrFail()
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\UI\API\Controllers;
|
||||
|
||||
use App\Containers\Education\Models\EducationalProgram;
|
||||
use App\Containers\Search\UI\API\Transformers\EducationalProgramSearchResource;
|
||||
use App\Ship\Controllers\Controller;
|
||||
use App\Ship\Enums\CacheKeys;
|
||||
use App\Ship\Enums\Education\EducationalProgramStatus;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ClientWidgetEducationalProgramController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return Cache::remember(
|
||||
CacheKeys::EDUCATION_PROGRAMS_PREFIX->value . 'search_list',
|
||||
now()->addDay(), // Кешируем на 1 день
|
||||
function () {
|
||||
return EducationalProgramSearchResource::collection(
|
||||
EducationalProgram::query()
|
||||
->where('status', EducationalProgramStatus::PUBLISHED)
|
||||
->orderBy('name', 'desc')
|
||||
->get()
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\UI\API\Controllers;
|
||||
|
||||
use App\Containers\Widget\Data\Rules\UniqueJsonField;
|
||||
use App\Containers\Widget\Enums\CustomFormStatus;
|
||||
use App\Containers\Widget\Models\CustomForm;
|
||||
use App\Containers\Widget\Models\CustomFormResponse;
|
||||
use App\Containers\Widget\UI\API\Transformers\FormResource;
|
||||
use App\Ship\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class ClientWidgetFormController extends Controller
|
||||
{
|
||||
public function single(string $id)
|
||||
{
|
||||
return new FormResource(CustomForm::query()->where('status', CustomFormStatus::PUBLISHED)->where('form_id', $id)->firstOrFail());
|
||||
}
|
||||
|
||||
public function submit(int $id, Request $request)
|
||||
{
|
||||
$data = CustomForm::findOrFail($id);
|
||||
|
||||
|
||||
$rules = $this->generateValidationRules($data['columns'], $data['id']);
|
||||
|
||||
|
||||
$messages = $this->generateValidationMessages($data['columns']);
|
||||
|
||||
|
||||
$validateData = Validator::make($request->all(), $rules, $messages);
|
||||
|
||||
|
||||
if ($validateData->fails()) {
|
||||
return response()->json($validateData->errors(), 422);
|
||||
}
|
||||
|
||||
$this->storeResponse($id, $validateData->validated());
|
||||
|
||||
|
||||
return response()->json([
|
||||
'message' => $data['send_message'],
|
||||
'status' => 'ok'
|
||||
]);
|
||||
}
|
||||
|
||||
private function generateValidationRules(array $columns, int $id): array
|
||||
{
|
||||
$rules = [];
|
||||
|
||||
foreach ($columns as $column) {
|
||||
// Извлекаем информацию о поле
|
||||
$name = $column['data']['name_field'];
|
||||
$rulesForField = [];
|
||||
|
||||
// Проверяем, является ли поле массивом (множественный выбор)
|
||||
if ($column['type'] === 'multiple_choice') {
|
||||
$rulesForField[] = 'required'; // Обязательно для множественного выбора
|
||||
$rulesForField[] = 'array'; // Указывает, что это массив
|
||||
$rulesForField[] = 'min:1'; // Минимум один элемент
|
||||
$rules[$name] = $rulesForField; // Правила для каждого элемента массива
|
||||
} else {
|
||||
// Обработка обычных полей
|
||||
if (!empty($column['data']['rules']['required'])) {
|
||||
$rulesForField[] = 'required';
|
||||
}
|
||||
|
||||
if (!empty($column['data']['rules']['min'])) {
|
||||
$rulesForField[] = 'min:' . $column['data']['rules']['min'];
|
||||
}
|
||||
|
||||
if (!empty($column['data']['rules']['max'])) {
|
||||
$rulesForField[] = 'max:' . $column['data']['rules']['max'];
|
||||
}
|
||||
|
||||
if (!empty($column['data']['rules']['unique']) && $column['data']['rules']['unique'] === true) {
|
||||
$rulesForField[] = new UniqueJsonField($id, $name);
|
||||
}
|
||||
|
||||
$rules[$name] = $rulesForField; // Добавляем правила для обычного поля
|
||||
}
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
private function generateValidationMessages(array $columns): array
|
||||
{
|
||||
$messages = [];
|
||||
|
||||
foreach ($columns as $column) {
|
||||
$name = $column['data']['name_field'];
|
||||
|
||||
if (!empty($column['data']['rules']['required'])) {
|
||||
$messages[$name . '.required'] = 'Поле обязательно для заполнения.';
|
||||
}
|
||||
|
||||
if (!empty($column['data']['rules']['min'])) {
|
||||
$messages[$name . '.min'] = 'Минимальная длина поля должна быть ' . $column['data']['rules']['min'] . ' символов.';
|
||||
}
|
||||
|
||||
if (!empty($column['data']['rules']['max'])) {
|
||||
$messages[$name . '.max'] = 'Максимальная длина поля должна быть ' . $column['data']['rules']['max'] . ' символов.';
|
||||
}
|
||||
|
||||
if (!empty($column['data']['rules']['unique'])) {
|
||||
$messages[$name . '.max'] = 'Поле должно быть уникальным';
|
||||
}
|
||||
}
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
private function storeResponse(int $id, array $validateData): void
|
||||
{
|
||||
CustomFormResponse::create([
|
||||
'custom_form_id' => $id,
|
||||
'answers' => $validateData,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\UI\API\Controllers;
|
||||
|
||||
use App\Containers\AppStructure\Models\Page;
|
||||
use App\Containers\Widget\UI\API\Transformers\PageNavigateResource;
|
||||
use App\Ship\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ClientWidgetPageController extends Controller
|
||||
{
|
||||
public function single(int $id): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$cacheKey = 'page_' . md5($id);
|
||||
|
||||
// Пытаемся получить данные из кеша
|
||||
$page = Cache::remember($cacheKey, now()->addHours(1), function () use ($id) {
|
||||
return Page::where('id', '=', $id)
|
||||
->with('section.pages.section', 'section.mainSection')
|
||||
->firstOrFail();
|
||||
});
|
||||
|
||||
if (isset($page->section)) {
|
||||
$breadcrumbs = [
|
||||
'mainSection' => $page->section->mainSection->title,
|
||||
'subSection' => $page->section->title,
|
||||
'page' => $page->title,
|
||||
];
|
||||
} else {
|
||||
$breadcrumbs = null;
|
||||
}
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'page' => new PageNavigateResource($page),
|
||||
'breadcrumbs' => $breadcrumbs
|
||||
],
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\UI\API\Controllers;
|
||||
|
||||
use App\Containers\Widget\Models\PageReferenceList;
|
||||
use App\Containers\Widget\UI\API\Transformers\PageReferenceListResource;
|
||||
use App\Ship\Controllers\Controller;
|
||||
use App\Ship\Enums\CacheKeys;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ClientWidgetPageReferenceListController extends Controller
|
||||
{
|
||||
public function show(string $slug)
|
||||
{
|
||||
return Cache::remember(
|
||||
CacheKeys::PAGE_REFERENCE_LIST_PREFIX->value . $slug,
|
||||
now()->addWeek(), // Кешируем на неделю, так как справочники меняются редко
|
||||
function () use ($slug) {
|
||||
return new PageReferenceListResource(
|
||||
PageReferenceList::query()
|
||||
->where('slug', $slug)
|
||||
->firstOrFail()
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\UI\API\Controllers;
|
||||
|
||||
use App\Containers\Article\Enums\PostStatus;
|
||||
use App\Containers\Article\Models\Post;
|
||||
use App\Containers\Widget\UI\API\Transformers\PostThumbnailResource;
|
||||
use App\Ship\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ClientWidgetPostController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$category_id = request()->input('category');
|
||||
$count = request()->input('count', 5);
|
||||
|
||||
$cacheKey = 'posts_' . $category_id . '_' . $count;
|
||||
|
||||
return Cache::remember($cacheKey, now()->addMinutes(10), function () use ($category_id, $count) {
|
||||
return PostThumbnailResource::collection(
|
||||
Post::query()
|
||||
->where('status', PostStatus::PUBLISHED)
|
||||
->when($category_id, function ($query, $category_id) {
|
||||
$query->where('category_id', $category_id);
|
||||
})
|
||||
->with('category')
|
||||
->orderBy('publish_at', 'desc')
|
||||
->take($count)
|
||||
->get()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public function single(int $id)
|
||||
{
|
||||
$cacheKey = 'post_' . $id;
|
||||
|
||||
return Cache::remember($cacheKey, now()->addMinutes(10), function () use ($id) {
|
||||
return new PostThumbnailResource(
|
||||
Post::query()->with('category')->find($id)->firstOrFail()
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\UI\API\Controllers;
|
||||
|
||||
use App\Containers\Widget\Models\Slider;
|
||||
use App\Ship\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ClientWidgetSliderController extends Controller
|
||||
{
|
||||
public function show(string $slug): ?object
|
||||
{
|
||||
$cacheKey = 'slider_' . $slug;
|
||||
|
||||
return Cache::remember($cacheKey, now()->addHour(), function () use ($slug) {
|
||||
$slider = Slider::query()
|
||||
->where('slug', $slug)
|
||||
->where('is_active', true)
|
||||
->with(['slides' => function($query) {
|
||||
$query->where('is_active', true);
|
||||
}])
|
||||
->firstOrFail();
|
||||
|
||||
return $slider ?: null;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use App\Containers\Widget\UI\API\Controllers\ClientWidgetAdditionalEducationalProgramController;
|
||||
use App\Containers\Widget\UI\API\Controllers\ClientWidgetContactController;
|
||||
use App\Containers\Widget\UI\API\Controllers\ClientWidgetEducationalProgramController;
|
||||
use App\Containers\Widget\UI\API\Controllers\ClientWidgetFormController;
|
||||
use App\Containers\Widget\UI\API\Controllers\ClientWidgetPageController;
|
||||
use App\Containers\Widget\UI\API\Controllers\ClientWidgetPageReferenceListController;
|
||||
use App\Containers\Widget\UI\API\Controllers\ClientWidgetPostController;
|
||||
use App\Containers\Widget\UI\API\Controllers\ClientWidgetSliderController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('/widget/get-posts', [ClientWidgetPostController::class, 'index'])->name('client.widget.post.index');
|
||||
|
||||
Route::get('/widget/get-posts/{id}', [ClientWidgetPostController::class, 'single'])->name('client.widget.post.single');
|
||||
|
||||
Route::get('/widget/get-additional-programs', [ClientWidgetAdditionalEducationalProgramController::class, 'index'])->name('client.widget.additional.program.index');
|
||||
|
||||
Route::get('/widget/get-educational-programs', [ClientWidgetEducationalProgramController::class, 'index'])->name('client.widget.educational.program.index');
|
||||
|
||||
Route::get('/widget/get-page-resource/{id}', [ClientWidgetPageReferenceListController::class, 'show'])->name('client.widget.page.resource.show');
|
||||
|
||||
Route::get('/widget/get-contact-widget/{id}', [ClientWidgetContactController::class, 'show'])->name('client.widget.contact.show');
|
||||
|
||||
Route::get('/widget/get-page/{path}', [ClientWidgetPageController::class, 'single'])->name('client.widget.page.single');
|
||||
|
||||
Route::get('/widget/get-form/{id}', [ClientWidgetFormController::class, 'single'])->middleware('rate.limited.check')->name('client.widget.form.single');
|
||||
|
||||
Route::post('/widget/get-form/{id}/submit', [ClientWidgetFormController::class, 'submit'])->middleware(['rate.limited.counter', 'rate.limited.check', 'form.time.period'])->name('client.widget.form.submit');
|
||||
|
||||
Route::get('/widget/get-slider/{slug}', [ClientWidgetSliderController::class, 'show'])->name('client.widget.slider.show');
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\UI\API\Transformers;
|
||||
|
||||
use App\Ship\Resources\JsonResource;
|
||||
|
||||
class ContactWidgetResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\UI\API\Transformers;
|
||||
|
||||
|
||||
use App\Ship\Resources\JsonResource;
|
||||
|
||||
class FormResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\UI\API\Transformers;
|
||||
|
||||
|
||||
use App\Ship\Resources\JsonResource;
|
||||
|
||||
class PageNavigateResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'slug' => $this->slug,
|
||||
'path' => $this->path,
|
||||
'is_url' => $this->is_url,
|
||||
'icon' => $this->icon
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\UI\API\Transformers;
|
||||
|
||||
|
||||
use App\Ship\Resources\JsonResource;
|
||||
|
||||
class PageReferenceListResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\UI\API\Transformers;
|
||||
|
||||
use App\Ship\Resources\JsonResource;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class PostThumbnailResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'slug' => $this->slug,
|
||||
'preview_text' => $this->preview_text,
|
||||
'category' => $this->category,
|
||||
'authors' => $this->authors,
|
||||
'preview' => $this->preview,
|
||||
'created_post' => Carbon::parse($this->publish_at)->diffforhumans(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user