` public static function CategoryState(int $state): ?string
{
$category = Category::find($ государство);
Код: Выделить всё
// foreach ($category as $descendant) {
if($category->id == $state){
if ($category->image_position == 'horizontal') {
return '16:9';
}
if ($category->image_position == 'vertical') {
return '1:1';
}
// if ($category){ return $category->image_position == 'horizontal'? '16:9' : '1:1';}
}
// }
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('category_id')
->label('Categoria')
->relationship('category', 'name')
->searchable()
->live(onBlur: true)
->preload()
->reactive(),
Forms\Components\TextInput::make('name')
->label('Nome')
->required()
->maxLength(255),
Forms\Components\TextInput::make('link')
->label('Link')
->required()
->url()
->maxLength(255)
->columnSpanFull(),
Forms\Components\Hidden::make('image_position'),
Forms\Components\FileUpload::make('image')
->label('Imagem')
->required()
->image()
->imageEditor()
->imageEditorMode(2)
->directory('projects')
->live(onBlur: true)
->imageCropAspectRatio(fn(Get $get) => self::categoryState($get('category_id'))),
Forms\Components\ToggleButtons::make('featured')
->label('Mostrar na home')
->inline()
->boolean()
->columnSpanFull(),
]);
}`
Подробнее здесь: https://stackoverflow.com/questions/787 ... n-filament
Мобильная версия