I want to have access to my menu on all front pages
I suggest you to write a view composer.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi guys, I am newbie to Laravel and this forum. I am currently learning Laravel (using version 10) and I have come across a problem. I want to have access to my menu on all front pages and I created the query in my appServiceProvider file like this:
$lang = request()->segment(1);
if (!empty($lang) && $lang !== 'admin') {
$activeLang =
Language::where('language_domain', $lang)->firstOrFail();
$navbar = Navigation::where('language_id', $activeLang->id)->where('navbar_status', 1)->get();
View::share('navbar', $navbar);
}
This code works on all routes (setlocale) except those that don't have a prefix and the prefix admin. Here is how I have my web.php setup:
Route::group([], function () {
require __DIR__ . '/auth.php';
});
Route::group([ 'prefix' => 'admin', 'middleware' => ['auth', 'verified'],], function () {
require __DIR__ . '/admin.php';
});
Route::get('/', function () { return Redirect::to("/sv"); });
Route::group([''prefix' => '{locale}', 'where' => ['locale' => '[a-zA-Z]{2}'], 'middleware' => ['setlocale']],
function () {
Route::get('/', [MainController::class, 'index'])->name('home');
Route::get('/{single:slug}', [MainController::class, 'single'])
->where(['single' => '[a-z0-9\-]+'])->name('single');
Route::get('/{category:slug}/{post:slug}', [MainController::class, 'double'])
->where(['category' => '[a-z0 9\-]+', 'post' => '[a-z0-9\-]+'])->name('double');
});
Could some one help me solve this. I am open to suggestions if there is a better way to solve it.
Best regards from Sweden.
I want to have access to my menu on all front pages
I suggest you to write a view composer.
Please or to participate in this conversation.