I have a navbar which is transparent on my mainpage, but I want to remove the transparent class and give it a new class with background color on a different blade template. I would use sections but it seems a bit overkill for me. Also I would like to prevent removing the layout and add it into the template itselves.
This my navbar in my app.blade.php
<nav id="nav" class="navbar fixed-top navbar-toggleable-md navbar-expand-lg navbar-transparent">
But in specific blade templates I want to remove that navbar-transparent class and give it "navbar-dark bg-dark"
<nav id="nav" class="navbar fixed-top navbar-toggleable-md navbar-expand-lg navbar-dark bg-dark">
Is there anything I can do besides using sections or removing the whole layout template and adding it to my custom blade templates?
In Controller method you can pass class as
$tempClass = "navbar-dark bg-dark";
return view("folder.view", compact("...your other arrays", "tempClass"));
In app.blade.php you can write,
@php
$tempClass = (!empty($tempClass) ? $tempClass : 'navbar-transparent')
@endphp
And replace
<nav id="nav" class="navbar fixed-top navbar-toggleable-md navbar-expand-lg navbar-transparent">
with
<nav id="nav" class="navbar fixed-top navbar-toggleable-md navbar-expand-lg {{ $tempClass }}">
So that you will get dynamic class name in app.blade.php