Share selected currency's symbol with every view using AppServiceProvider instead of loading it from separate controllers
MODIFY
app/Providers/AppServiceProvider.php
app/Providers/AppServiceProvider.php
@@ -10,7 +10,8 @@ class AppServiceProvider extends ServiceProvider {
public function boot() {
view()->composer('*', function($view) {
$view->with([
- 'userName' => Auth::check() ? Auth::user()->name : null
+ 'userName' => Auth::check() ? Auth::user()->name : null,
+ 'currency' => Auth::check() ? Auth::user()->currency->symbol : null
]);
});
}

MODIFY
resources/views/dashboard.blade.php
resources/views/dashboard.blade.php
<div class="row row--gutter row--responsive mt-3 mb-4">
<div class="row__column">
<div class="card card--blue">
- <h2 style="font-size: 20px;">{!! $currency->symbol !!} {{ number_format($totalSpendings / 100, 2) }}</h2>
+ <h2 style="font-size: 20px;">{!! $currency !!} {{ number_format($totalSpendings / 100, 2) }}</h2>
<div class="mt-1" style="color: #A7AEBB;">{{ __('general.total_spent') }}</div>
</div>
</div>
<div class="color-dark">{{ $spending->description }}</div>
<div class="mt-1" style="font-size: 14px;">{{ $spending->formatted_happened_on }}</div>
</div>
- <div class="row__column row__column--compact row__column--middle color-dark">{!! $currency->symbol !!} {{ $spending->formatted_amount }}</div>
+ <div class="row__column row__column--compact row__column--middle color-dark">{!! $currency !!} {{ $spending->formatted_amount }}</div>
</div>
@endforeach
@else
</div>
<div class="row__column row__column--middle">
<div class="color-dark">{{ $tag->name }}</div>
- <div class="mt-1" style="font-size: 14px; font-weight: 600;">{!! $currency->symbol !!} {{ number_format($tag->amount / 100, 2) }}</div>
+ <div class="mt-1" style="font-size: 14px; font-weight: 600;">{!! $currency !!} {{ number_format($tag->amount / 100, 2) }}</div>
</div>
</div>
@endforeach

MODIFY
resources/views/recurrings/index.blade.php
resources/views/recurrings/index.blade.php
<a href="/recurrings/{{ $recurring->id }}">{{ $recurring->description }}</a>
</div>
<div class="row mt-1">
- <div class="row__column row__column--compact" style="font-size: 14px; font-weight: 600;">{!! $currency->symbol !!} {{ number_format($recurring->amount / 100, 2) }}</div>
+ <div class="row__column row__column--compact" style="font-size: 14px; font-weight: 600;">{!! $currency !!} {{ number_format($recurring->amount / 100, 2) }}</div>
@if ($recurring->due_days)
<div class="row__column row__column--compact ml-2" style="font-size: 14px; font-weight: 600;"><i class="far fa-clock"></i> Due in {{ $recurring->due_days }} days</div>
@endif

Share selected currency's symbol with every view using AppServiceProvider instead of loading it from separate controllers