I'm trying to utilize the Laravel landing page route. For example Laravel takes you to the welcome page by default, and it has no url text after the slash.
Route::get('/', function () {
return view('welcome');
});
In my welcome page I'm using following condition to apply styling based on the route name.
{!! Route::is('/')? 'class="index"':'' !!}
However this code doesn't work. How can I check the route of the welcome page properly?
Edit: Using "Request" instead of "Route" makes it work. However for consistency's sake I would like to know if it can be done using "Route" too.
try this
@if(Request::is('/'))
class="index"
@endif
or more simply
if(Request::is('/')) {
class="index"
}
Try this:
<li class="@if (request()->is('/')) index @endif"></li>
// ...
</li>
You can use wildcards as well with this:
<li class="@if (request()->is('/some-url/*')) active @endif">
// ...
</li>
Name your route and use this name to condition your styling
Route::get('/', function () {
return view('welcome');
})->name('home');
In your blade
{!! (Route::currentRouteName() == 'home')? 'class="index"':'' !!}
尝试这个:
<li {!! Request::is('/') ? 'class=index' : '' !!}>...</li>
Route::get('/', function () {
return view('welcome');
})->name('home');
in blade
class = "default class @if(\Request::route()->getName() == 'home')your_class @endif"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.