本文整理汇总了PHP中Laravel\Spark\Spark::validateRegistrationsWith方法的典型用法代码示例。如果您正苦于以下问题:PHP Spark::validateRegistrationsWith方法的具体用法?PHP Spark::validateRegistrationsWith怎么用?PHP Spark::validateRegistrationsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Laravel\Spark\Spark
的用法示例。
在下文中一共展示了Spark::validateRegistrationsWith方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: customizeRegistration
/**
* Customize Spark's new user registration logic.
*
* @return void
*/
protected function customizeRegistration()
{
Spark::validateRegistrationsWith(function (Request $request) {
return ['name' => 'required|max:255', 'email' => 'required|email|unique:users', 'password' => 'required|confirmed|min:6', 'terms' => 'required|accepted'];
});
// Spark::createUsersWith(function (Request $request) {
// // Return New User Instance...
// });
}
示例2: customizeRegistration
/**
* Customize Spark's new user registration logic.
*
* @return void
*/
protected function customizeRegistration()
{
if (Spark::basedInEU()) {
Spark::validateRegistrationsWith(function (Request $request, $withSubscription = false) {
$userRules = ['name' => 'required|max:255', 'email' => 'required|email|unique:users', 'password' => 'required|confirmed|min:6', 'terms' => 'required|accepted'];
$addressRules = ['street' => 'required', 'city' => 'required', 'zip' => 'required', 'country' => 'required', 'vat_id' => 'vat_number'];
return $withSubscription ? array_merge($userRules, $addressRules) : $userRules;
});
}
// Spark::validateSubscriptionsWith(function (Request $request) {
// return [
// 'plan' => 'required',
// 'terms' => 'required|accepted',
// 'stripe_token' => 'required',
// ];
// });
// Spark::createUsersWith(function (Request $request) {
// // Return New User Instance...
// });
/**
* To comply with the EU VAT regulations we need to pass
* the user's address, IP and company name to stripe.
* This data will also be used for the invoices.
*/
if (Spark::basedInEU()) {
Spark::createSubscriptionsWith(function (Request $request, $user, $subscription) {
/**
* Apply tax rate from the given country.
* If a valid VAT ID is given, the VAT
* rate will be set to 0.
*/
$user->setTaxForCountry($request->country, $request->has('vat_id'));
$subscription->create($request->stripe_token, ['email' => $user->email, 'description' => $user->name, 'metadata' => ['ip' => $request->getClientIp(), 'company' => $request->company, 'vat_id' => $request->vat_id, 'tax_percent' => $user->getTaxPercent()]]);
});
}
/**
* Apply the tax rate of the customer to the invoice
* when swapping plans.
*/
if (Spark::basedInEU()) {
Spark::swapSubscriptionsWith(function (Request $request, $user) {
$user->subscription($request->plan)->maintainTrial()->prorate()->swap();
$customer = $user->subscription()->getStripeCustomer();
\Stripe\Invoice::create(['customer' => $customer->id, 'tax_percent' => $customer->metadata->tax_percent], $user->getStripeKey())->pay();
});
}
}