Ad
Dynamic Url Segment Name In Laravel 5.1
In fact i'm looking for way to fetch url segment and replace it to another string name for example /setting
show it in my view الضبط
in Arabic
After research i found substr_replace
or str_ireplace
can achieve that
as the following:
$seg2 = request()->segment(2);
($seg2 == 'setting') ? $seg2 = str_ireplace($seg2,'الضبط',$seg2) : $seg2 = str_ireplace($seg2,'another_segment_name', $seg2);
I see this approach is very bad if i have many of different routes can to be in $seg2
place .
If there any other way can achieve that please help me ,Thanks
Ad
Answer
Thanks @The Alpha for your help in fact i have been achieved my needs now but i did some changes to achieve it i will show it for help any somebody else needs to do that
at first i created segments.php
file in resources/lang/ar
and change local language to ar
in config/app.php
and in segments.php
<?php
// Segments Array for navigation paths on view
return [
'users' => 'المستخدمين', //maybe to be seg2
'settings' => 'الضبط', //also maybe to be seg2
];
and in my view
<!-- Simple condition to check if user on segment 2 or not and fetch the proper segment name according to incoming segment in url -->
{{(request()->segment(2) != '') ? trans('segments.'.request()->segment(2)) : '' }}
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad