laravellaravel-bladelaravel-10laravel-breeze

what are the different attributes one can use for x-nav-link?


I recently installed Laravel Framework 10.43.0 and then installed Laravel Breeze into that, which created a bunch of new files, including resources/views/layouts/navigation.blade.php. In that file there's this:

<!-- Navigation Links -->
<div class="hidden space-x-8 sm:-my-px sm:ms-10 sm:flex">
    <x-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
        {{ __('Dashboard') }}
    </x-nav-link>
</div>

I can add new nav links by adding new x-nav-link elements but my question is... what are the valid : attributes for x-nav-link? There's :href and :active... anything else?

I ask because I'd like to make a nav link appear conditionally based on whether or not you're an admin for the site and I'm curious if there's a built in way to do that with the x-nav-link element.


Solution

  • Other than :href and :active, it also supports standard html attributes like :class, :target and any other anchor <a> tag specific attribute

    While Laravel breeze does not have any built in attribute to handle protected link link in your case. You can use Laravel built-in authorization by implementing the @can blade directive which can be used like this in your code:

    @can('admin')
    <x-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
        {{ __('Dashboard') }}
    </x-nav-link>
    

    @endcan

    You can add other protection depending on your need