Files
backend-mm/app/Nova/Resources/CMS/Media/Carousel.php
2025-09-25 03:03:31 +05:00

191 lines
5.1 KiB
PHP

<?php
namespace App\Nova\Resources\CMS\Media;
use App\Models\CMS\Media\Carousel as CarouselModel;
use App\Models\System\Settings\OS;
use App\Nova\Filters\AppTypeFilter;
use App\Nova\Filters\VisableFilter;
use App\Nova\Resource;
use App\Repositories\CMS\Media\Banner\BannerRepository;
use Ebess\AdvancedNovaMediaLibrary\Fields\Images;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\URL;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Panel;
use Outl1ne\NovaSortable\Traits\HasSortableRows;
use Trin4ik\NovaSwitcher\NovaSwitcher;
class Carousel extends Resource
{
/**
* Sortable behavior
*/
use HasSortableRows;
/**
* The model the resource corresponds to.
*
* @var class-string<CarouselModel>
*/
public static $model = CarouselModel::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'id';
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'title',
];
/**
* The relationships that should be eager loaded on index queries.
*
* @var array
*/
public static $with = ['media'];
/**
* Get the displayable label of the resource.
*/
public static function label(): string
{
return __('Carousels');
}
/**
* Get the displayable singular label of the resource.
*/
public static function singularLabel(): string
{
return __('Carousel');
}
/**
* Get the fields displayed by the resource.
*/
public function fields(NovaRequest $request): array
{
return [
new Panel(__('Basic information'), [
ID::make()->sortable(),
Images::make(__('Image'), 'main')
->conversionOnIndexView('thumb50x50')
->rules('required')
->required(),
Select::make(__('App'), 'app')
->displayUsingLabels()
->searchable()
->options(OS::apps())
->default(OS::WEBSITE)
->rules('required'),
Select::make(__('Place'), 'place')
->displayUsingLabels()
->searchable()
->options(CarouselModel::places())
->default('homepage')
->rules('required'),
Text::make(__('Name'), 'title')
->translatable()
->rules('nullable', 'string', 'max:255'),
URL::make(__('Link'), 'link')
->displayUsing(fn () => $this->link)
->rules('nullable', 'string', 'max:2048')
->hideFromIndex(),
NovaSwitcher::make(__('Is visible'), 'is_visible')
->default(true)
->sortable(),
]),
new Panel(__('Additional information'), [
Select::make(__('Resource type to attach'), 'resource_type')
->displayUsingLabels()
->searchable()
->options(CarouselModel::attachableResources())
->rules('nullable')
->onlyOnForms(),
Select::make(__('Resource to attach'), 'resource_id')
->displayUsingLabels()
->searchable()
->rules('nullable')
->dependsOn(['resource_type'], function ($field, $request, $formData) {
if ($formData->resource_type) {
$field->options(BannerRepository::getNovaResource($formData->resource_type))->rules('required');
}
})
->onlyOnForms(),
Text::make(
__('Attached resource'),
fn () => view('vendor.nova.resources.banner.resource-type', ['resource' => $this])->render()
)->asHtml()->hideFromIndex(),
Text::make(__('Note'), 'description')
->translatable()
->rules('nullable', 'string', 'max:255')
->hideFromIndex(),
]),
];
}
/**
* Get the cards available for the request.
*
* @return array
*/
public function cards(NovaRequest $request)
{
return [];
}
/**
* Get the filters available for the resource.
*
* @return array
*/
public function filters(NovaRequest $request)
{
return [
new VisableFilter(),
new AppTypeFilter(),
];
}
/**
* Get the lenses available for the resource.
*
* @return array
*/
public function lenses(NovaRequest $request)
{
return [];
}
/**
* Get the actions available for the resource.
*
* @return array
*/
public function actions(NovaRequest $request)
{
return [];
}
}