feat(social-media): add 'orden' field to social media pivot table and update related functionality
This commit is contained in:
@@ -28,7 +28,8 @@ class SocialMedia extends Model
|
||||
'code',
|
||||
'codigo'
|
||||
)
|
||||
->withPivot('url')
|
||||
->withTimestamps();
|
||||
->withPivot(['url', 'orden'])
|
||||
->withTimestamps()
|
||||
->orderByPivot('orden');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,8 +107,9 @@ class Tenant extends Model
|
||||
'codigo',
|
||||
'code'
|
||||
)
|
||||
->withPivot('url')
|
||||
->withTimestamps();
|
||||
->withPivot(['url', 'orden'])
|
||||
->withTimestamps()
|
||||
->orderByPivot('orden');
|
||||
}
|
||||
|
||||
public function menues(): BelongsToMany
|
||||
|
||||
@@ -71,6 +71,7 @@ class StoreTenantRequest extends FormRequest
|
||||
Rule::exists('social_media', 'code'),
|
||||
],
|
||||
'social_media.*.url' => ['required', 'url', 'max:2048'],
|
||||
'social_media.*.orden' => ['sometimes', 'integer', 'min:0', 'distinct'],
|
||||
'hero_config' => ['nullable', 'array'],
|
||||
'hero_config.title_html' => ['nullable', 'string'],
|
||||
'hero_config.description_html' => ['nullable', 'string'],
|
||||
|
||||
@@ -82,6 +82,7 @@ class UpdateTenantRequest extends FormRequest
|
||||
Rule::exists('social_media', 'code'),
|
||||
],
|
||||
'social_media.*.url' => ['required', 'url', 'max:2048'],
|
||||
'social_media.*.orden' => ['sometimes', 'integer', 'min:0', 'distinct'],
|
||||
'hero_config' => ['nullable', 'array'],
|
||||
'hero_config.title_html' => ['nullable', 'string'],
|
||||
'hero_config.description_html' => ['nullable', 'string'],
|
||||
|
||||
@@ -197,14 +197,17 @@ class TenantService
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array{code: string, url: string}> $socialMedia
|
||||
* @param array<int, array{code: string, url: string, orden?: int}> $socialMedia
|
||||
*/
|
||||
private function syncSocialMedia(Tenant $tenant, array $socialMedia): void
|
||||
{
|
||||
$associations = [];
|
||||
|
||||
foreach ($socialMedia as $item) {
|
||||
$associations[$item['code']] = ['url' => $item['url']];
|
||||
foreach (array_values($socialMedia) as $index => $item) {
|
||||
$associations[$item['code']] = [
|
||||
'url' => $item['url'],
|
||||
'orden' => $item['orden'] ?? $index,
|
||||
];
|
||||
}
|
||||
|
||||
$tenant->socialMedia()->sync($associations);
|
||||
|
||||
Reference in New Issue
Block a user