Example of View composers in monicahq/monica

File app/Http/ViewComposers/CurrencySelectViewComposer.php (link to Github)
use Illuminate\View\View;
use App\Models\Settings\Currency;

class CurrencySelectViewComposer
{
    public function compose(View $view)
    {
        $currencies = Currency::orderBy('name', 'asc')->get();
        $view->with('currencies', $currencies);
    }
}
File resources/views/partials/components/currency-select.blade.php (link to Github)
<select name="currency_id" id="currency_id" class="form-control" required>
  @foreach ( $currencies as $currency )
    @if ($currency->id == $selectionID)
    <option value="{{ $currency->id }}" selected>{{ $currency->name }}</option>
    @else
    <option value="{{ $currency->id }}" >{{ $currency->name }}</option>
    @endif
  @endforeach
</select>

Additional resources on view composers: