OneCode ЧАТ
Открыть в Telegram
Общаемся на тему веб-разработки. HTML, CSS, JS, VueJS, NuxtJS, PHP, Laravel, MySQL, PostgreSQL. Разрешено: - Задавать вопросы. - Отвечать на вопросы. - Делиться своим опытом. Запрещено: - Нецензурные выражения. - Спам, реклама, фл
БольшеСтрана не указанаКатегория не указана
485
Подписчики
Нет данных24 часа
Нет данных7 дней
Нет данных30 дней
Архив постов
485
// app/Models/Balance
protected $fillable = [
'user_id',
'server_id',
'balance',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function server(): BelongsTo
{
return $this->belongsTo(Server::class);
}
// app/Models/Donat
protected $fillable = [
'user_id',
'server_id',
'donat',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function server(): BelongsTo
{
return $this->belongsTo(Server::class);
}
// app/Models/Server
public function donates(): HasMany
{
return $this->hasMany(Donat::class);
}
public function balances(): HasMany
{
return $this->hasMany(Balance::class);
}
// app/Models/User
// Из модели можно убрать поле `balance`
public function balance(): Attribute
{
return Attribute::make(
get: fn ($value, $attributes) => $attributes['balances']->sum('balance'),
);
}
public function balances(): HasMany
{
return $this->hasMany(Balance::class);
}
public function donates(): HasMany
{
return $this->hasMany(Donat::class);
}485
Ништяк, вечно забываю про него
$data = array_map( fn( $val ): string => "$val", array_values( $data ) );485
Если ограничения в RAM нет можешь не юзать пласк для удобства собственной сортировки. Если есть то сразу в пласк и массив как ты делал. Но по идее там сразу приходят в массиве
485
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Group::make()
->schema([
Forms\Components\Section::make()
->schema([
Forms\Components\TextInput::make('name')
->required()
->live(onBlur: true)
->maxLength(255)
->unique(ignoreRecord: true)
->afterStateUpdated(function (
string $operation, $state, Forms\Set $set) {
// if ($operation !== 'create') {
// return;
// }
$set('slug', Str::slug($state));
}),
Forms\Components\TextInput::make('slug')
->disabled()
->dehydrated()
->required()
->unique(Product::class, 'slug', ignoreRecord: true),
Forms\Components\MarkdownEditor::make('description')
->columnSpanFull(),
])->columns(2),
Forms\Components\Section::make('Pricing & Inventory')
->schema([
Forms\Components\TextInput::make('sku')
->label("SKU (Stock Keeping Unit)")
->unique(ignoreRecord: true)
->required(),
Forms\Components\TextInput::make('price')
->numeric()
->rules('regex:/^\d+(\.\d{1,2})?$/')
->required(),
Forms\Components\TextInput::make('quantity')
->numeric()
->minValue(0)
->maxValue(100)
->required(),
Forms\Components\Select::make('type')
->options([
'downloadable' => ProductTypeEnum::DOWNLOADABLE->value,
'deliverable' => ProductTypeEnum::DELIVERABLE->value,
])
->required()
->native(false),
])->columns(2),
]),
Forms\Components\Group::make()
->schema([
Forms\Components\Section::make('Status')
->schema([
Forms\Components\Toggle::make('is_visible')
->label('Visibility')
->helperText('Enable or disable product visibility')
->default(true),
Forms\Components\Toggle::make('is_featured')
->label('Featured')
->helperText('Enable or disable product featured status'),
Forms\Components\DatePicker::make('published_at')
->label('Availability')
->native(false)
->default(now()),
]),
