Comment #⁨4⁩

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.

  1. In reply to Toby Toby

    Ahhh, I see, the alternative you've provided with the closure looks cleaner 👍️, thanks! I shouldn't have missed that in the docs 😅.

    Okay, that makes sense, I'll use the resolveRelationUsing method for adding relationships. Is there any way we can add traits to the Waterhole\Models\User class in a similar way as adding relationships via the resolveRelationUsing method? I wanted to use this Laravel package, Overtrue\LaravelFavorite, but it requires the use of traits on the User model. I want to use this package to allow users to favourite my own models.

  2. In reply to Toby Toby

    Also, regarding conditional rendering, the use of a closure doesn't seem to work with the Extend remove method as it only accepts a string param. Is this method going to be updated in the future to allow for mixed content instead of only strings? I was trying to conditionally remove some of the buttons in the text editor but it seems they are hard coded, so using the replace method wasn't viable (source code).