Comment #⁨3⁩

In reply to Stormlight Stormlight

I was able to figure out my question above regarding conditional rendering. If anyone else is interested, I just removed the 'search' component and added my own custom component (which has the logic for the conditional rendering) via the WaterHoleServiceProvider. Waterhole docs for reference.

// WaterholeServiceProvider

use App\View\Components\Navigation;

public function extend(): void
{
    Extend\Header::remove('search');
    Extend\Header::add(Navigation::class); // my own custom Blade component
}
// My custom blade view (navigation.blade.php)

<div>
    {{-- Other nav links if needed --}}
    @if (Route::is('waterhole.*'))
        <x-waterhole::HeaderSearch />
    @endif
</div>
  1. Toby Toby Waterhole Founder Apr 11, 2024
    In reply to Stormlight Stormlight

    Yep, that's right about conditional rendering - there's a note on this in the Extenders doc. The way you've done it works well, or an alternative would be to replace the search component with a closure and conditionally return the search component:

    use Waterhole\View\Components\HeaderSearch;
    
    Extend\Header::replace('search', fn() => Route::is('waterhole.*') ? HeaderSearch::class : null);

    Regarding adding relationships to Waterhole's User model, using resolveRelationUsing is fine when you're interacting with a package like Waterhole – the Laravel docs are talking about "normal application development" as in within your own app's codebase. Creating your own subclass of the Waterhole User model is also a nice idea, although I'm not 100% certain it will work in all cases as I believe some instances of the User model are hardcoded throughout Waterhole's codebase – I will definitely look at making this configurable in the future.