Laravel 504 Gateway Time-outが出てしまう
解決したいこと
laravelでマルチログインを実行中で、admin側をseederで作成して、ログインを実行すると
おそらくログインはできているが、Laravel 504 Gateway Time-outが出てしまう
解決策を教えてください。
該当するソースコード
web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Auth\AuthController;
use App\Http\Controllers\Admin\AdminController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('home/top');
});
Auth::routes();
//新規作成後マイページ
Route::get('home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
// プロフィール編集
Route::get('edit',[App\Http\Controllers\HomeController::class. 'edit'])->name('edit');
Route::group(['prefix' => 'admin'], function() {
// ログイン画面
Route::get('login', [App\Http\Controllers\Admin\LoginController::class, 'showLoginForm'])->name('admin.login');
// ログイン処理
Route::post('loginLogin', [App\Http\Controllers\Admin\LoginController::class, 'loginLogin'])->name('loginLogin');
// その後の遷移(ログイン後)
Route::get('adminHome', [App\Http\Controllers\Admin\HomeController::class, 'adminHome'])->name('adminHome');
});
Route::group(['prefix' => 'admin', 'middleware' => 'auth:admin'], function() {
Route::post('logout', 'Admin\LoginController@logout')->name('admin.logout');
});
LoginController
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
// protected $redirectTo = RouteServiceProvider::HOME;
protected $redirectTo = '/admin/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest:admin')->except('logout');
}
// adminログインページ
public function showLoginForm()
{
return view('admin.login');
}
//adminログイン処理
public function loginLogin(Request $request)
{
$credentials = $request->only(['email', 'password']);
if (Auth::guard('admin')->attempt($credentials)) {
return redirect()->route('adminHome')->with([
'login_msg' => 'ログインしました。',
]);
}
return back()->withErrors([
'login' => ['ログインに失敗しました'],
]);
}
// public function login(Request $request)
// {
// $this->validate($request, [
// 'email' => 'email|required',
// 'password' => 'required|min:4'
// ]);
// if (Auth::attempt(['email' => $request->input('email'), 'password' => $request->input('password')])) {
// return redirect()->route('admin.index');
// }
// return back()->withErrors([
// 'login' => 'メールアドレスかパスワードが間違っています.',
// ]);
// }
protected function guard()
{
return Auth::guard('admin'); //変更
}
}
config auth.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
// 'guard' => 'web',
'guard' => 'user',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'user' => [
'driver' => 'session',
'provider' => 'users',
],
'admin' => [ //追加
'driver' => 'session', //追加
'provider' => 'admins', //追加
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Models\Admin::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that each reset token will be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
'admin' =>[
'provider' => 'admin',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
]
],
/*
|--------------------------------------------------------------------------
| Password Confirmation Timeout
|--------------------------------------------------------------------------
|
| Here you may define the amount of seconds before a password confirmation
| times out and the user is prompted to re-enter their password via the
| confirmation screen. By default, the timeout lasts for three hours.
|
*/
'password_timeout' => 10800,
];
自分で試したこと
おそらく,
public function loginLogin(Request $request)
{
$credentials = $request->only(['email', 'password']);
if (Auth::guard('admin')->attempt($credentials)) {
return redirect()->route('adminHome')->with([
'login_msg' => 'ログインしました。',
]);
}
return back()->withErrors([
'login' => ['ログインに失敗しました'],
]);
}
の記述が問題なのかなとお思っています。
なぜダメなのかがわかりません。
解決策教えてください。。
0