LaravelのSocialiteを使っています。
Githubの認証を使ってログインを実装しようとしていて、下記のコードを書きました。
LoginController.php
1<?php 2 3namespace App\Http\Controllers\Auth; 4 5use App\Http\Controllers\Controller; 6use Illuminate\Foundation\Auth\AuthenticatesUsers; 7use Socialite;// 追加! 8use Illuminate\Http\Request;// 追加! 9use Illuminate\Support\Facades\DB; 10 11class LoginController extends Controller 12{ 13 /* 14 |-------------------------------------------------------------------------- 15 | Login Controller 16 |-------------------------------------------------------------------------- 17 | 18 | This controller handles authenticating users for the application and 19 | redirecting them to your home screen. The controller uses a trait 20 | to conveniently provide its functionality to your applications. 21 | 22 */ 23 24 use AuthenticatesUsers; 25 26 /** 27 * Where to redirect users after login. 28 * 29 * @var string 30 */ 31 protected $redirectTo = '/home'; 32 33 /** 34 * Create a new controller instance. 35 * 36 * @return void 37 */ 38 public function __construct() 39 { 40 $this->middleware('guest')->except('logout'); 41 } 42 43 /** 44 * GitHubの認証ページヘユーザーをリダイレクト 45 * 46 * @return \Illuminate\Http\Response 47 */ 48 public function redirectToProvider()// 追加! 49 { 50 return Socialite::driver('github')->scopes(['read:user', 'public_repo'])->redirect(); 51 } 52 53 /** 54 * GitHubからユーザー情報を取得 55 * 56 * @return \Illuminate\Http\Response 57 */ 58 public function handleProviderCallback(Request $request) 59 { 60 $github_user = Socialite::driver('github')->user(); 61 62 $now = date("Y/m/d H:i:s"); 63 $app_user = DB::select('select * from public.user where github_id = ?', [$github_user->user['login']]); 64 if (empty($app_user)) { 65 DB::insert('insert into public.user (github_id, created_at, updated_at) values (?, ?, ?)', [$github_user->user['login'], $now, $now]); 66 } 67 $request->session()->put('github_token', $github_user->token); 68 69 return redirect('github'); 70 }
すると下記のエラーが表示されます。
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_PARSE) syntax error, unexpected end of file, expecting function (T_FUNCTION) or const (T_CONST)
ファイルの最後に予期しない内容が書かれているというのは何となくわかるのですが、
(T_FUNCTION) or const (T_CONST)
というのが何なのか、ググっても出てこないので詰まっております。
エラーの解決策がおわかりでしたら、ご教示ください。よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー