本文整理汇总了PHP中Laravel\Spark\Spark::user方法的典型用法代码示例。如果您正苦于以下问题:PHP Spark::user方法的具体用法?PHP Spark::user怎么用?PHP Spark::user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Laravel\Spark\Spark
的用法示例。
在下文中一共展示了Spark::user方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: current
/**
* Get the current discount for the given user.
*
* @param Request $request
* @param string $userId
* @return Response
*/
public function current(Request $request, $userId)
{
$user = Spark::user()->where('id', $userId)->firstOrFail();
if ($coupon = $this->coupons->forBillable($user)) {
return response()->json($coupon->toArray());
}
}
示例2: store
/**
* Create a discount for the given user.
*
* @param Request $request
* @param string $userId
* @return Response
*/
public function store(Request $request, $userId)
{
$user = Spark::user()->where('id', $userId)->firstOrFail();
$this->validate($request, ['type' => 'required|in:amount,percent', 'value' => 'required|integer', 'duration' => 'required|in:once,forever,repeating', 'months' => 'required_if:duration,repeating']);
$coupon = StripeCoupon::create(['currency' => 'usd', 'amount_off' => $request->type == 'amount' ? $request->value * 100 : null, 'percent_off' => $request->type == 'percent' ? $request->value : null, 'duration' => $request->duration, 'duration_in_months' => $request->months, 'max_redemptions' => 1], config('services.stripe.secret'));
$user->applyCoupon($coupon->id);
}
示例3: getCurrentUser
/**
* Get the current user of the application.
*
* @return \Illuminate\Http\Response
*/
public function getCurrentUser()
{
$user = Spark::user();
if (Spark::usingTeams()) {
$user->currentTeam;
}
return $user->withHidden(['last_four', 'extra_billing_info']);
}
示例4: handle
/**
* {@inheritdoc}
*/
public function handle($team, $email)
{
$invitedUser = Spark::user()->where('email', $email)->first();
$this->emailInvitation($invitation = $this->createInvitation($team, $email, $invitedUser));
if ($invitedUser) {
event(new UserInvitedToTeam($team, $invitedUser));
}
return $invitation;
}
示例5: getCurrentUser
/**
* Get the current user of the application.
*
* @return \Illuminate\Http\Response
*/
public function getCurrentUser()
{
$user = Spark::user();
if (Spark::usingTeams()) {
$user->currentTeam;
}
$user->subscriptions;
return $user->withHidden(['card_brand', 'card_last_four', 'extra_billing_info']);
}
示例6: stopImpersonating
/**
* Stop impersonating and switch back to primary account.
*
* @param Request $request
* @return Response
*/
public function stopImpersonating(Request $request)
{
$currentId = Auth::id();
// We will make sure we have an impersonator's user ID in the session and if the
// value doesn't exist in the session we will log this user out of the system
// since they aren't really impersonating anyone and manually hit this URL.
if (!$request->session()->has('spark:impersonator')) {
Auth::logout();
return redirect('/');
}
$userId = $request->session()->pull('spark:impersonator');
// After removing the impersonator user's ID from the session so we can retrieve
// the original user. Then, we will flush the entire session to clear out any
// stale data from while we were doing the impersonation of the other user.
$request->session()->flush();
Auth::login(Spark::user()->findOrFail($userId));
return redirect('/spark/kiosk#/users/' . $currentId);
}
示例7: login
/**
* Login via the emergency token.
*
* @param Request $request
* @return Response
*/
public function login(Request $request)
{
$this->validate($request, ['token' => 'required']);
// If there is no authentication ID stored in the session, it means that the user
// hasn't made it through the login screen so we'll just redirect them back to
// the login view. They must have hit the route manually via a specific URL.
if (!$request->session()->has('spark:auth:id')) {
return redirect('login');
}
$user = Spark::user()->findOrFail($request->session()->pull('spark:auth:id'));
// Here we will check this hash of the token against the stored hash of the reset
// token to make sure they match. If they don't match then the emergency token
// is invalid so we'll redirect back out with an error message for the user.
$resetCode = $user->two_factor_reset_code;
if (!Hash::check($request->token, $resetCode)) {
return redirect('login')->withErrors(['token' => 'The emergency token was invalid.']);
}
// If the token was valid we will login this user after disabling the two-factor
// authentication settings so that they don't get stuck again. They will then
// re-enable two-factor authentication in their settings if they so choose.
$this->disableTwoFactorAuth($user);
Auth::login($user, $request->session()->pull('spark:auth:remember', false));
return redirect()->intended($this->redirectPath());
}
示例8: trialUsers
/**
* Get the number of users who are on a generic trial.
*
* @return Response
*/
public function trialUsers()
{
return Spark::user()->where('trial_ends_at', '>=', Carbon::now())->count();
}
示例9: verifyToken
/**
* Verify the given authentication token.
*
* @param Request $request
* @return Response
*/
public function verifyToken(Request $request)
{
$this->validate($request, ['token' => 'required']);
// If there is no authentication ID stored in the session, it means that the user
// hasn't made it through the login screen so we'll just redirect them back to
// the login view. They must have hit the route manually via a specific URL.
if (!$request->session()->has('spark:auth:id')) {
return redirect('login');
}
$user = Spark::user()->findOrFail($request->session()->pull('spark:auth:id'));
// Next, we'll verify the actual token with our two-factor authentication service
// to see if the token is valid. If it is, we can login the user and send them
// to their intended location within the protected part of this application.
if (Spark::interact(Verify::class, [$user, $request->token])) {
Auth::login($user, $request->session()->pull('spark:auth:remember', false));
return redirect()->intended($this->redirectPath());
} else {
return back();
}
}
示例10: create
/**
* {@inheritdoc}
*/
public function create(array $data)
{
$user = Spark::user();
$user->forceFill(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'last_read_announcements_at' => Carbon::now(), 'trial_ends_at' => Carbon::now()->addDays(Spark::trialDays())])->save();
return $user;
}