In reply to
Stormlight
Stormlight
Apr 3, 2024
Thanks for clarifying that @Toby! I had two more questions:
How can we implement conditional rendering of components based on the route. In my case, I’m trying to remove the ‘search’ component from t...
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>
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: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.