Set locale from query parameter

This commit is contained in:
Benjamin Beganović 2021-03-18 15:41:26 +01:00
parent 69eecbf281
commit 3bcb65efc2
3 changed files with 31 additions and 6 deletions

View File

@ -15,16 +15,36 @@ namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller;
use App\Models\BillingSubscription;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
class BillingSubscriptionPurchaseController extends Controller
{
public function index(BillingSubscription $billing_subscription)
public function index(BillingSubscription $billing_subscription, Request $request)
{
if ($request->has('locale')) {
$this->setLocale($request->query('locale'));
}
return view('billing-portal.purchase', [
'billing_subscription' => $billing_subscription,
'hash' => Str::uuid()->toString(),
'request_data' => $request->all(),
]);
}
/**
* Set locale for incoming request.
*
* @param string $locale
*/
private function setLocale(string $locale): void
{
$record = DB::table('languages')->where('locale', $locale)->first();
if ($record) {
App::setLocale($record->locale);
}
}
}

View File

@ -130,6 +130,13 @@ class BillingPortalPurchase extends Component
*/
public $quantity = 1;
/**
* First-hit request data (queries, locales...).
*
* @var array
*/
public $request_data;
/**
* Handle user authentication
*
@ -246,8 +253,6 @@ class BillingPortalPurchase extends Component
'quantity' => $this->quantity,
];
dd($data);
$this->invoice = $this->billing_subscription
->service()
->createInvoice($data)
@ -290,7 +295,7 @@ class BillingPortalPurchase extends Component
return $this->quantity;
}
// TODO: David for review.
// TODO: Dave review.
if ($this->quantity >= $this->billing_subscription->max_seats_limit) {
return $this->quantity;
}

View File

@ -2,7 +2,7 @@
@section('meta_title', $billing_subscription->product->product_key)
@section('body')
@livewire('billing-portal-purchase', ['billing_subscription' => $billing_subscription, 'contact' => auth('contact')->user(), 'hash' => $hash])
@livewire('billing-portal-purchase', ['billing_subscription' => $billing_subscription, 'contact' => auth('contact')->user(), 'hash' => $hash, 'request_data' => $request_data])
@stop
@push('footer')