add Slug Helper

This commit is contained in:
aslan 2024-03-12 12:40:40 +03:00
parent 40414f6da8
commit 66fdb9d7b0
3 changed files with 22 additions and 14 deletions

View File

@ -0,0 +1,18 @@
<?php
namespace App\Helpers;
use Illuminate\Support\Str;
class SlugHelper
{
public static function get(array $validated): string
{
if ($validated['slug'] === null) {
$transliterationSlug = Str::slug($validated['name']);
$randomNumber = random_int(100, 999);
return "{$transliterationSlug}-{$randomNumber}";
}
return $validated['slug'];
}
}

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers\admin\Catalog\Direction; namespace App\Http\Controllers\admin\Catalog\Direction;
use App\Helpers\SlugHelper;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Requests\admin\Catalog\Direction\StoreDirectionProfileRequest; use App\Http\Requests\admin\Catalog\Direction\StoreDirectionProfileRequest;
use App\Http\Requests\admin\Catalog\Direction\UpdateDirectionProfileRequest; use App\Http\Requests\admin\Catalog\Direction\UpdateDirectionProfileRequest;
@ -31,13 +32,7 @@ class DirectionProfileController extends Controller
{ {
$validated = $request->validated(); $validated = $request->validated();
if ($validated['slug'] === null) { $slug = SlugHelper::get($validated);
$transliterationSlug = Str::slug($validated['name']);
$randomNumber = random_int(100, 999);
$slug = "{$transliterationSlug}-{$randomNumber}";
} else {
$slug = $validated['slug'];
}
$directionProfile = new DirectionProfile(); $directionProfile = new DirectionProfile();
$directionProfile->name = $validated['name']; $directionProfile->name = $validated['name'];

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers\admin\Catalog; namespace App\Http\Controllers\admin\Catalog;
use App\Helpers\SlugHelper;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Requests\admin\Catalog\StoreFacultyRequest; use App\Http\Requests\admin\Catalog\StoreFacultyRequest;
use App\Http\Requests\admin\Catalog\UpdateFacultyRequest; use App\Http\Requests\admin\Catalog\UpdateFacultyRequest;
@ -33,13 +34,7 @@ class FacultyController extends Controller
{ {
$validated = $request->validated(); $validated = $request->validated();
if ($validated['slug'] === null) { $slug = SlugHelper::get($validated);
$transliterationSlug = Str::slug($validated['name']);
$randomNumber = random_int(100, 999);
$slug = "{$transliterationSlug}-{$randomNumber}";
} else {
$slug = $validated['slug'];
}
$faculty = new Faculty(); $faculty = new Faculty();
$faculty->name = $validated['name']; $faculty->name = $validated['name'];