我想将我的 Laravel 应用程序与 Strava 集成。我创建了一个名为StravaModel
以下内容的模型:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use GuzzleHttp\Client;
class StravaModel extends Model
{
private $client_id;
private $client_secret;
private $redirect_uri;
private $client;
private $strava_uri = 'https://www.strava.com/api/v3';
public function __construct()
{
$this->client_id = env('CT_STRAVA_CLIENT_ID', ''); # Strava Client ID
$this->client_secret = env('CT_STRAVA_SECRET_ID', ''); # Strava Secrect
$this->redirect_uri = env('CT_STRAVA_REDIRECT_URI', ''); # Strava Redirect URi
$this->client = new Client();
}
public function connectStrava()
{
return redirect($this->returnStravaUrl());
}
public function returnStravaUrl()
{
return('https://www.strava.com/oauth/authorize?client_id='. $this->client_id .'&response_type=code&redirect_uri='. $this->redirect_uri . '&scope=read_all,profile:read_all,activity:read_all&state=strava');
}
}
在我的控制器中,我执行以下操作:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\StravaModel;
class StravaController extends Controller
{
public function index(Request $request)
{
$stravaModel = new StravaModel();
$stravaModel->connectStrava();
}
}
我的路由文件如下所示:
<?php
use Illuminate\Support\Facades\Route;
Auth::routes();
Route::group(['middleware' => ['auth', 'verified']], function() {
Route::get('/strava', 'StravaController@index')->name('strava');
});
Route::get('/home', 'HomeController@index')->name('home');
但是我只是得到一个空白屏幕,为什么页面没有重定向到 strava 誓言?