Torann / laravel-currency

This provides Laravel with currency functions such as currency formatting and conversion using up-to-date exchange rates.
http://lyften.com/projects/laravel-currency
BSD 2-Clause "Simplified" License
390 stars 138 forks source link

Currency picker sample for better documentation #135

Open officialmmt opened 4 years ago

officialmmt commented 4 years ago

I tryed to do something for currency picker laravel 7 but don't understand how we change default currency to selected currency. How I should use "?currency=usd" query parameter because when I type to url nothing happens. Need some examples to do this for blade, route. I have just some blade

<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    {{ currency()->getUserCurrency() }} <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu">
                      @foreach(currency()->getCurrencies() as $currency)
                    <li>
                      <a href="{{url('currency=' . $currency['code']) }}">
                      {{ $currency['name'] }}
                      </a>
                    </li>
                    @endforeach
                    </ul>

Can you help please?

tariqdev commented 3 years ago
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> {{ currency()->getUserCurrency() }} <span class="caret"></span> </button>
<ul class="dropdown-menu">
    @foreach(currency()->getCurrencies() as $currency)
        <li>
            <a href="{{url('currency?currency='.$currency['code'])}}"> {{ $currency['name'] }} </a>
        </li>
    @endforeach
</ul>

Route Route::get('currency', ['uses'=>'CurrencyController@set']);

Controller


public function set(Request $request)
{
    if($request->get('currency')){
        currency()->setUserCurrency($request);
    }
    return back();
}
Torann commented 3 years ago

There is a middleware that handles the currency query param

See the Middleware section here https://lyften.com/projects/laravel-currency/doc/