first commit
This commit is contained in:
87
app/Http/Controllers/Frontend/ProgramDetailController.php
Normal file
87
app/Http/Controllers/Frontend/ProgramDetailController.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Frontend;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Admin\program;
|
||||
use App\Models\Admin\Testimonial;
|
||||
use App\Models\Admin\country;
|
||||
use App\Models\Admin\blog_category;
|
||||
use App\Models\Admin\blog;
|
||||
use App\Models\Admin\ProgramCurrencyAmount;
|
||||
use AmrShawky\LaravelCurrency\Facade\Currency;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class ProgramDetailController extends Controller {
|
||||
|
||||
public function single_program_detail($id) {
|
||||
// $convert_to = $request->input('convert_to');
|
||||
$testimonial = Testimonial::with('country')
|
||||
->get()
|
||||
->toArray();
|
||||
$blog_three = blog::latest()
|
||||
->limit(3)
|
||||
->get();
|
||||
$blog_categ = blog_category::latest()
|
||||
->limit(2)
|
||||
->get()
|
||||
->toArray();
|
||||
$single_program_details = program::with('programe_amount', 'programe_images','programe_country')
|
||||
->find($id)
|
||||
->toArray();
|
||||
$show_program = program::latest()->limit(2)->get()->toArray();
|
||||
return view('Frontend.Pages.Program.program_detail')
|
||||
->with(['single_program_detail' => $single_program_details,
|
||||
'test' => $testimonial,
|
||||
'programs' => $show_program,
|
||||
'blog_muilti' => $blog_three,
|
||||
'blog_category' => $blog_categ,]);
|
||||
}
|
||||
|
||||
public function fetch_single_prog_currency_amount(Request $request) {
|
||||
$programId = $request->input('program_id');
|
||||
$convert_to = $request->input('convert_to');
|
||||
|
||||
$currency = ProgramCurrencyAmount::where('programs_xid', $programId)
|
||||
->select('usd_price', 'week')
|
||||
->get();
|
||||
|
||||
$convertedAmounts = [];
|
||||
|
||||
foreach ($currency as $data) {
|
||||
$usdPrice = $data->usd_price;
|
||||
$week = $data->week;
|
||||
if ($convert_to == 'One') {
|
||||
$convert_name = 'GBP';
|
||||
} else if ($convert_to == 'Two') {
|
||||
$convert_name = 'USD';
|
||||
} else {
|
||||
$convert_name = 'EUR';
|
||||
}
|
||||
|
||||
|
||||
$fromCurrency = 'GBP';
|
||||
$apiKey = config('services.exchangerates.api_key');
|
||||
$baseUrl = 'https://api.apilayer.com/exchangerates_data_api/latest';
|
||||
|
||||
$client = new Client();
|
||||
// $response = $client->get("{$baseUrl}?access_key={$apiKey}");
|
||||
$response = \Http::get('https://api.freecurrencyapi.com/v1/latest?apikey=fca_live_IUpn22wjq5zhcvRqGix4k6FlOZKo9SOHSAobRtMd');
|
||||
$data = json_decode($response->getBody(), true);
|
||||
|
||||
$conversionRate = $data['data'][$convert_name] / $data['data'][$fromCurrency];
|
||||
$convertedAmount = $usdPrice * $conversionRate;
|
||||
|
||||
|
||||
$convertedAmounts[] = [
|
||||
'week' => $week,
|
||||
'convert_name' => $convert_name,
|
||||
'usd_price' => $usdPrice,
|
||||
'converted_amount' => $convertedAmount
|
||||
];
|
||||
}
|
||||
return response()->json($convertedAmounts);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user