azizyus/currencymanager

Some fancy exchange calculations and currency crud

0.8.1 2019-02-17 22:57 UTC

README

StyleCI

Documentation


What Does This Package Do?

This package basically provides "Currency CRUD" and "A Helper Which is Helps You to Choose Your Currency In FrontSide And Stores As Session" so you dont need to worry about managing your currencies

Installation

Step 1

composer require azizyus/currencymanager

Step 2

Add

CurrencyManager\CurrencyManagerServiceProvider::class,
Former\FormerServiceProvider::class,
to config/app.php

Step 3 (Migrations)

php artisan vendor:publish --tag=azizyus/currencymanager-publish-migrations
Im already loading migrations with ->loadMigrationsFrom, but if it doenst work just publish them and use it
(that means you can migrate without publishing but in case if you want to override or etc... just do it as i said)

Config File

php artisan vendor:publish --tag=azizyus/currencymanager-publish-config



return [

'usePackageRoutes'         => true,
'middleWares'              => ['web'],
'prefix'                   => 'currency',
'frontPrefix'              => 'currency_front',
'frontMiddlewares'         => ['web'],
'controllerNamespace'      => 'CurrencyManager\Controllers',
'frontControllerNamespace' => 'CurrencyManager\Controllers',

];

As i mentioned at first, this package helps you too choose your currency in frontside so you have some config parameters about them, you can change both of middlewares and prefixes or namespaces

Routes

I'm using Route::resource routes for crud operations for default and they are;
currency.index
currency.edit
currency.update
currency.create
currency.store
currency.delete
and because of these also you need to pass {{method_fields(' ')}} if you want to customize package also there is front routes to change your currency;


route("currency.change",["id"=>"_YOUR_CURRENCY_ID"]);
route("currency.current");
last one shows your current currency as json for more like testing purposes i dont think anyone want to use that

Controllers

You will be have 2 controller in package; CurrencyController, which is gives crud operations and CurrencyFrontController and this one gives you currency changing feature, you can inheritance them and change some specific parts of like a edit page's view file or you can pass a modified repository with some of your specific operations

FAQ

What does CurrencyHelper do?

It manages your selected currency via sessions for you, all you need is; take instance and ->getCurrencyOrDefault(); and if you dont have any error ($currencyHelperInstance->errorThrower->hasError) you can use your currency safely

I want to exchange my currency with another one what to do?

I got CurrencyExchangeCalculator for that, pass your base and target currency Instances to ctor and ->setPrice(); then you can calculate right price by ->baseToTarget();

I need to use my own controllers what to do?

Just extend one of my controllers and currencyManager config file should look like this;

return [
'usePackageRoutes'         => true,
'middleWares'              => ['web'],
'prefix'                   => 'currency',
'frontPrefix'              => 'currency_front',
'frontMiddlewares'         => ['web'],
'controllerNamespace'      => "App\\Http\\Controllers",
'frontControllerNamespace' => "App\\Http\\Controllers",

];

i already inherited my controller what to do?

CurrencyController updated in b1678f7c so you get these methods as trait but still you need to change config file