This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
site-base/spark/src/Http/Controllers/TokenController.php
2017-11-03 16:26:07 +11:00

45 lines
948 B
PHP

<?php
namespace Laravel\Spark\Http\Controllers;
use Illuminate\Http\Request;
use Laravel\Spark\Contracts\Repositories\TokenRepository;
class TokenController extends Controller
{
/**
* The token repository instance.
*
* @var TokenRepository
*/
protected $tokens;
/**
* Create a new controller instance.
*
* @param TokenRepository $tokens
* @return void
*/
public function __construct(TokenRepository $tokens)
{
$this->tokens = $tokens;
$this->middleware('auth');
}
/**
* Exchange the current transient API token for a new one.
*
* @param Request $request
* @return Response
*/
public function refresh(Request $request)
{
$this->tokens->deleteExpiredTokens($request->user());
return response('Refreshed.')->withCookie(
$this->tokens->createTokenCookie($request->user())
);
}
}