laravel-currency icon indicating copy to clipboard operation
laravel-currency copied to clipboard

Currency picker sample for better documentation

Open officialmmt opened this issue 5 years ago • 2 comments

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?

officialmmt avatar Jul 08 '20 14:07 officialmmt

<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();
}

tariqdev avatar Sep 09 '20 12:09 tariqdev

There is a middleware that handles the currency query param

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

Torann avatar Oct 29 '20 13:10 Torann