Laravel blade - Add a class if a condition is met
Something like this?
{{ HTML::linkRoute('hostesses.index', 'Archived', $params, array('class' => $hostess->active ? 'btn btn-info' : 'btn btn-default')) }}
Now we can use conditional classes with @class
directive like this
@php
$isActive = false;
$hasError = true;
@endphp
<span @class([
'p-4',
'font-bold' => $isActive,
'text-gray-500' => ! $isActive,
'bg-red' => $hasError,
])></span>
https://laravel.com/docs/8.x/blade#conditional-classes
You could do this:
// App/Http/routes.php
Route::get('foo/bar', 'FooController@bar);
// Your blade file
<li class="{{ Request::path() == 'foo/bar' ? 'active' : '' }}">
<a href="{{ url('foo/bar') }}"></i> Bar</a>
</li>
There is also another option:
<li class="@if(Request::is('/')) is-active @endif">
<a href="{{ route('index') }}">Home</a>
</li>