# views/partials/menus.blade.php @php $navLinks = [ 'Home' => route('home.index'), 'Contact' => route('contact.index'), 'About' => route('about.index'), ]; @endphp <div> @foreach($navLinks as $name => $link) <a href="{{ $link }}">{{ $name }}</a> @endforeach </div>
Another approach is to define it using a normal "php" opening and closing tag.
<?php $name = "PostSrc"; ?>
And with that, you can call the variable name inside the blade itself after the location of the code definition.
<h1>{{ $name }}</h2>
Leave a reply