CurrencyController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\Currency;
  5. class CurrencyController extends Controller
  6. {
  7. public function changeCurrency(Request $request)
  8. {
  9. $currency = Currency::where('code', $request->currency_code)->first();
  10. $request->session()->put('currency_code', $request->currency_code);
  11. $request->session()->put('currency_symbol', $currency->symbol);
  12. $request->session()->put('currency_exchange_rate', $currency->exchange_rate);
  13. flash(translate('Currency changed to ').$currency->name)->success();
  14. }
  15. public function currency(Request $request)
  16. {
  17. $sort_search =null;
  18. $currencies = Currency::orderBy('created_at', 'desc');
  19. if ($request->has('search')){
  20. $sort_search = $request->search;
  21. $currencies = $currencies->where('name', 'like', '%'.$sort_search.'%');
  22. }
  23. $currencies = $currencies->paginate(10);
  24. $active_currencies = Currency::where('status', 1)->get();
  25. return view('backend.setup_configurations.currencies.index', compact('currencies', 'active_currencies','sort_search'));
  26. }
  27. public function updateYourCurrency(Request $request)
  28. {
  29. $currency = Currency::findOrFail($request->id);
  30. $currency->name = $request->name;
  31. $currency->symbol = $request->symbol;
  32. $currency->code = $request->code;
  33. $currency->exchange_rate = $request->exchange_rate;
  34. $currency->status = $currency->status;
  35. if($currency->save()){
  36. flash(translate('Currency updated successfully'))->success();
  37. return redirect()->route('currency.index');
  38. }
  39. else {
  40. flash(translate('Something went wrong'))->error();
  41. return redirect()->route('currency.index');
  42. }
  43. }
  44. public function create()
  45. {
  46. return view('backend.setup_configurations.currencies.create');
  47. }
  48. public function edit(Request $request)
  49. {
  50. $currency = Currency::findOrFail($request->id);
  51. return view('backend.setup_configurations.currencies.edit', compact('currency'));
  52. }
  53. public function store(Request $request)
  54. {
  55. $currency = new Currency;
  56. $currency->name = $request->name;
  57. $currency->symbol = $request->symbol;
  58. $currency->code = $request->code;
  59. $currency->exchange_rate = $request->exchange_rate;
  60. $currency->status = '0';
  61. if($currency->save()){
  62. flash(translate('Currency updated successfully'))->success();
  63. return redirect()->route('currency.index');
  64. }
  65. else {
  66. flash(translate('Something went wrong'))->error();
  67. return redirect()->route('currency.index');
  68. }
  69. }
  70. public function update_status(Request $request)
  71. {
  72. $currency = Currency::findOrFail($request->id);
  73. if($request->status == 0){
  74. if (get_setting('system_default_currency') == $currency->id) {
  75. return 0;
  76. }
  77. }
  78. $currency->status = $request->status;
  79. $currency->save();
  80. return 1;
  81. }
  82. }