如何解决Header.blade 组件区域设置开关 - LARAVEL 8如何?
我正在尝试让我的语言环境前缀适用于我的所有路由。
它通常有效,但我遇到了这个问题,其中标题语言按钮正在寻找来自特定页面的参数(我认为)。
<li><a href="{{ route(Route::CurrentRouteName(),'nl') }}">nl</a></li>
<li><a href="{{ route(Route::CurrentRouteName(),'fr') }}">fr</a></li>
<li><a href="{{ route(Route::CurrentRouteName(),'en') }}">en</a></li>
在我的标题组件中。
一旦我尝试打开基于变量作为路由参数的页面,我就会收到错误消息: routing-error-message
Web.PHP
Route::redirect('/','/nl');
Route::prefix('/{locale}')->group(function () {
Route::get('/','App\Http\Controllers\Controller@showLanding')->name('home');
Route::get('intenties-van-de-site','App\Http\Controllers\IntentionsController@showIntentionsSite')->name('intenties-van-de-site');
Route::get('intenties-bij-een-ontwerp','App\Http\Controllers\IntentionsController@showIntentionsproject')->name('intenties-bij-een-ontwerp');
Route::get('architectuur','App\Http\Controllers\ArchitectureController@showArchitecture')->name('architectuur');
Route::get('architectuur/{project}','App\Http\Controllers\ArchitectureController@showProject')->name('project-title');
});
<a href="{{ route('project-title',['project' => '1978-reel-boom','locale' => app()->getLocale() ]) }}">
<img alt="1978 Reel Boom" title="1978 Reel Boom" src="{img url}">
<p>1978 Reel Boom</p>
</a>
有没有办法修复头部路由?
提前致谢!
一个菜鸟
解决方法
Route::CurrentRouteName()
为您提供命名路线,但您缺少参数。
您可以使用 request()->route()->parameters
获取参数数组。
例如,对于 url '/en/architectuur/something'
,转储 request()->route()->parameters
会返回以下数组。
[
'lang' => 'en','project' => 'something'
]
然后,您只需使用 array_merge
更改 lang 键。
@foreach (['nl','fr','en'] as $lang)
@php($params = array_merge(request()->route()->parameters,['lang' => $lang]))
<li>
<a href="{{ route(Route::CurrentRouteName(),$params) }}">nl</a>
</li>
@endforeach
如果您愿意,也可以内联
@foreach (['nl','en'] as $lang)
<li>
<a href="{{ route(Route::CurrentRouteName(),array_merge(request()->route()->parameters,['lang' => $lang])) }}">nl</a>
</li>
@endforeach
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。