質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Q&A

解決済

1回答

5338閲覧

LaravelのSocialiteで発生したsyntax error, unexpected end of fileエラーの解決策について

mbase

総合スコア17

Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

0グッド

0クリップ

投稿2019/04/21 02:28

編集2019/04/21 02:30

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)

というのが何なのか、ググっても出てこないので詰まっております。

エラーの解決策がおわかりでしたら、ご教示ください。よろしくお願い致します。

イメージ説明

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2019/04/21 02:35

提示したコードはファイルの全体ですか?
guest

回答1

0

ベストアンサー

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 } 71} //これがないからでしょう

投稿2019/04/21 02:36

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

mbase

2019/04/21 04:12

ありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問