Commit 45c59e25 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix string truncation overflow across the system

Audited all varchar-limited columns vs code that generates values for them:

- BranchForm: validation was max:20 but column is varchar(10) — fixed
- ActivityService: Str::slug output now capped at 90 chars (column is 100)
- TrainingProgramService: same slug truncation fix
- SetupWizard: slug generation for activities/programs also truncated
- Logout: removed navigate:true (app→guest layout cross breaks)

Affected columns and their limits:
  branches.code = varchar(10) ✓ fixed
  training_groups.code = varchar(10) ✓ already validated
  activities.slug = varchar(100) ✓ now truncated
  training_programs.slug = varchar(100) ✓ now truncated
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent f75532dc
......@@ -13,12 +13,12 @@ class ActivityService
public function create(array $data, User $actor): Activity
{
return DB::transaction(function () use ($data, $actor) {
$slug = $data['slug'] ?? Str::slug($data['name']);
$slug = Str::limit($data['slug'] ?? Str::slug($data['name']), 90, '');
// Check slug uniqueness within academy
$exists = Activity::where('slug', $slug)->exists();
if ($exists) {
$slug .= '-' . Str::random(4);
$slug = Str::limit($slug, 85, '') . '-' . Str::random(4);
}
return Activity::create([
......
......@@ -13,10 +13,10 @@ class TrainingProgramService
public function create(array $data, User $actor): TrainingProgram
{
return DB::transaction(function () use ($data, $actor) {
$slug = $data['slug'] ?? Str::slug($data['name']);
$slug = Str::limit($data['slug'] ?? Str::slug($data['name']), 90, '');
$exists = TrainingProgram::where('slug', $slug)->exists();
if ($exists) {
$slug .= '-' . Str::random(4);
$slug = Str::limit($slug, 85, '') . '-' . Str::random(4);
}
return TrainingProgram::create(array_merge($data, [
......
......@@ -13,7 +13,7 @@ public function logout(): void
session()->invalidate();
session()->regenerateToken();
$this->redirect(route('login'), navigate: true);
$this->redirect(route('login'));
}
public function render()
......
......@@ -68,7 +68,7 @@ public function rules(): array
return [
'name' => 'required|string|max:255',
'name_ar' => 'required|string|max:255',
'code' => 'required|string|max:20',
'code' => 'required|string|max:10',
'phone' => 'nullable|string|max:20',
'email' => 'nullable|email|max:255',
'address' => 'nullable|string',
......
......@@ -374,7 +374,7 @@ public function completeSetup(): void
'academy_id' => $academyId,
'name_ar' => $activityData['name_ar'],
'name' => $activityData['name'] ?: $activityData['name_ar'],
'slug' => Str::slug($activityData['name_ar']),
'slug' => Str::limit(Str::slug($activityData['name_ar']), 90, ''),
'category' => $activityData['category'],
'description' => $activityData['description'] ?? null,
'is_active' => true,
......@@ -394,7 +394,7 @@ public function completeSetup(): void
'activity_id' => $activity->id,
'name_ar' => $programData['name_ar'],
'name' => $programData['name_ar'],
'slug' => Str::slug($programData['name_ar']),
'slug' => Str::limit(Str::slug($programData['name_ar']), 90, ''),
'program_duration_weeks' => $durationMonths * 4,
'max_participants' => (int) $programData['max_participants'],
'status' => 'active',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment