add Slug Helper
This commit is contained in:
parent
40414f6da8
commit
66fdb9d7b0
|
@ -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'];
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers\admin\Catalog\Direction;
|
||||
|
||||
use App\Helpers\SlugHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\admin\Catalog\Direction\StoreDirectionProfileRequest;
|
||||
use App\Http\Requests\admin\Catalog\Direction\UpdateDirectionProfileRequest;
|
||||
|
@ -31,13 +32,7 @@ class DirectionProfileController extends Controller
|
|||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
if ($validated['slug'] === null) {
|
||||
$transliterationSlug = Str::slug($validated['name']);
|
||||
$randomNumber = random_int(100, 999);
|
||||
$slug = "{$transliterationSlug}-{$randomNumber}";
|
||||
} else {
|
||||
$slug = $validated['slug'];
|
||||
}
|
||||
$slug = SlugHelper::get($validated);
|
||||
|
||||
$directionProfile = new DirectionProfile();
|
||||
$directionProfile->name = $validated['name'];
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers\admin\Catalog;
|
||||
|
||||
use App\Helpers\SlugHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\admin\Catalog\StoreFacultyRequest;
|
||||
use App\Http\Requests\admin\Catalog\UpdateFacultyRequest;
|
||||
|
@ -33,13 +34,7 @@ class FacultyController extends Controller
|
|||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
if ($validated['slug'] === null) {
|
||||
$transliterationSlug = Str::slug($validated['name']);
|
||||
$randomNumber = random_int(100, 999);
|
||||
$slug = "{$transliterationSlug}-{$randomNumber}";
|
||||
} else {
|
||||
$slug = $validated['slug'];
|
||||
}
|
||||
$slug = SlugHelper::get($validated);
|
||||
|
||||
$faculty = new Faculty();
|
||||
$faculty->name = $validated['name'];
|
||||
|
|
Loading…
Reference in New Issue