0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Laravel11 マルチログイン 作業内容まとめ

Last updated at Posted at 2025-04-22

まとめ

- DB関連
# 用意するファイル
モデル: Admin.php 参考:web/html/laravel11/app/Models/User.php
マイグレーション : 1000_01_01_000000_create_admins_table.php 参考:web/html/laravel11/database/migrations/0001_01_01_000000_create_users_table.php
シーダー: AdminSeeder.php UserSeeder.php

- config
web/html/laravel11/config/auth.php
'guards' に admin ガード追加
'providers' に admins プロバイダ追加
'passwords' に admins ブローカー追加

.env
追加
SESSION_COOKIE_ADMIN=アプリ名_admin_session 


- view
resources/views/auth をコピーして、resources/views/adminの下に ペーストして、route()の中身などをadmin用に編集
web/html/laravel11/resources/views/admin/auth/login.blade.php をシンプルにする。

- ルーティング
web/html/laravel11/bootstrap/app.php で管理者用のルーティングファイルが使える様に編集
web/html/laravel11/routes/admin.php を作成 参考:web/html/laravel11/routes/auth.php
apiを使うことを考慮して web/html/laravel11/routes/api.php を作成

- フォームリクエスト
app/Http/Requests/Auth/LoginRequest.php をコピーして、app/Http/Requests/Auth/AdminLoginRequest.php を作成

- Controller
app/Http/Controllers/Auth をコピーして、app/Http/Controllers/Admin/Auth を作成
変更箇所: ネームスペース、ルーティング、モデルUser->Admin

- Providers
app/Providers/AppServiceProvider.php に admin用のsessionを設定

gitで変更した箇所確認

マルチログイン
diff --git a/web/html/laravel11/.env.example b/web/html/laravel11/.env.example
index a48af6b..7a4d1b3 100644
--- a/web/html/laravel11/.env.example
+++ b/web/html/laravel11/.env.example
@@ -76,4 +76,6 @@ AWS_DEFAULT_REGION=us-east-1
 AWS_BUCKET=
 AWS_USE_PATH_STYLE_ENDPOINT=false
 
-VITE_APP_NAME="${APP_NAME}"
\ No newline at end of file
+VITE_APP_NAME="${APP_NAME}"
+
+SESSION_COOKIE_ADMIN=laravel_admin_session 
\ No newline at end of file
diff --git a/web/html/laravel11/app/Http/Controllers/Admin/Auth/AuthenticatedSessionController.php b/web/html/laravel11/app/Http/Controllers/Admin/Auth/AuthenticatedSessionController.php
new file mode 100644
index 0000000..f890df4
--- /dev/null
+++ b/web/html/laravel11/app/Http/Controllers/Admin/Auth/AuthenticatedSessionController.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Auth;
+
+use App\Http\Controllers\Controller;
+use App\Http\Requests\Auth\AdminLoginRequest;
+use Illuminate\Http\RedirectResponse;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
+use Illuminate\View\View;
+
+class AuthenticatedSessionController extends Controller
+{
+    /**
+     * Display the login view.
+     */
+    public function create(): View
+    {
+        return view('admin.auth.login');
+    }
+
+    /**
+     * Handle an incoming authentication request.
+     */
+    public function store(AdminLoginRequest $request): RedirectResponse
+    {
+        $request->authenticate();
+
+        $request->session()->regenerate();
+
+        return redirect()->intended(route('admin.dashboard', absolute: false));
+    }
+
+    /**
+     * Destroy an authenticated session.
+     */
+    public function destroy(Request $request): RedirectResponse
+    {
+        Auth::guard('admin')->logout();
+
+        $request->session()->invalidate();
+
+        $request->session()->regenerateToken();
+
+        return redirect('/');
+    }
+}
diff --git a/web/html/laravel11/app/Http/Controllers/Admin/Auth/ConfirmablePasswordController.php b/web/html/laravel11/app/Http/Controllers/Admin/Auth/ConfirmablePasswordController.php
new file mode 100644
index 0000000..d0a3d4a
--- /dev/null
+++ b/web/html/laravel11/app/Http/Controllers/Admin/Auth/ConfirmablePasswordController.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Auth;
+
+use App\Http\Controllers\Controller;
+use Illuminate\Http\RedirectResponse;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
+use Illuminate\Validation\ValidationException;
+use Illuminate\View\View;
+
+class ConfirmablePasswordController extends Controller
+{
+    /**
+     * Show the confirm password view.
+     */
+    public function show(): View
+    {
+        return view('admin.auth.confirm-password');
+    }
+
+    /**
+     * Confirm the user's password.
+     */
+    public function store(Request $request): RedirectResponse
+    {
+        if (! Auth::guard('admin')->validate([
+            'email' => $request->user()->email,
+            'password' => $request->password,
+        ])) {
+            throw ValidationException::withMessages([
+                'password' => __('auth.password'),
+            ]);
+        }
+
+        $request->session()->put('admin.auth.password_confirmed_at', time());
+
+        return redirect()->intended(route('admin.dashboard', absolute: false));
+    }
+}
diff --git a/web/html/laravel11/app/Http/Controllers/Admin/Auth/EmailVerificationNotificationController.php b/web/html/laravel11/app/Http/Controllers/Admin/Auth/EmailVerificationNotificationController.php
new file mode 100644
index 0000000..64381ad
--- /dev/null
+++ b/web/html/laravel11/app/Http/Controllers/Admin/Auth/EmailVerificationNotificationController.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Auth;
+
+use App\Http\Controllers\Controller;
+use Illuminate\Http\RedirectResponse;
+use Illuminate\Http\Request;
+
+class EmailVerificationNotificationController extends Controller
+{
+    /**
+     * Send a new email verification notification.
+     */
+    public function store(Request $request): RedirectResponse
+    {
+        if ($request->user()->hasVerifiedEmail()) {
+            return redirect()->intended(route('dashboard', absolute: false));
+        }
+
+        $request->user()->sendEmailVerificationNotification();
+
+        return back()->with('status', 'verification-link-sent');
+    }
+}
diff --git a/web/html/laravel11/app/Http/Controllers/Admin/Auth/EmailVerificationPromptController.php b/web/html/laravel11/app/Http/Controllers/Admin/Auth/EmailVerificationPromptController.php
new file mode 100644
index 0000000..abf50f3
--- /dev/null
+++ b/web/html/laravel11/app/Http/Controllers/Admin/Auth/EmailVerificationPromptController.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Auth;
+
+use App\Http\Controllers\Controller;
+use Illuminate\Http\RedirectResponse;
+use Illuminate\Http\Request;
+use Illuminate\View\View;
+
+class EmailVerificationPromptController extends Controller
+{
+    /**
+     * Display the email verification prompt.
+     */
+    public function __invoke(Request $request): RedirectResponse|View
+    {
+        return $request->user()->hasVerifiedEmail()
+                    ? redirect()->intended(route('admin.dashboard', absolute: false))
+                    : view('admin.auth.verify-email');
+    }
+}
diff --git a/web/html/laravel11/app/Http/Controllers/Admin/Auth/NewPasswordController.php b/web/html/laravel11/app/Http/Controllers/Admin/Auth/NewPasswordController.php
new file mode 100644
index 0000000..26094ea
--- /dev/null
+++ b/web/html/laravel11/app/Http/Controllers/Admin/Auth/NewPasswordController.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Auth;
+
+use App\Http\Controllers\Controller;
+use App\Models\User;
+use Illuminate\Auth\Events\PasswordReset;
+use Illuminate\Http\RedirectResponse;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Hash;
+use Illuminate\Support\Facades\Password;
+use Illuminate\Support\Str;
+use Illuminate\Validation\Rules;
+use Illuminate\View\View;
+
+class NewPasswordController extends Controller
+{
+    /**
+     * Display the password reset view.
+     */
+    public function create(Request $request): View
+    {
+        return view('admin.auth.reset-password', ['request' => $request]);
+    }
+
+    /**
+     * Handle an incoming new password request.
+     *
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function store(Request $request): RedirectResponse
+    {
+        $request->validate([
+            'token' => ['required'],
+            'email' => ['required', 'email'],
+            'password' => ['required', 'confirmed', Rules\Password::defaults()],
+        ]);
+
+        // Here we will attempt to reset the user's password. If it is successful we
+        // will update the password on an actual user model and persist it to the
+        // database. Otherwise we will parse the error and return the response.
+        $status = Password::reset(
+            $request->only('email', 'password', 'password_confirmation', 'token'),
+            function (User $user) use ($request) {
+                $user->forceFill([
+                    'password' => Hash::make($request->password),
+                    'remember_token' => Str::random(60),
+                ])->save();
+
+                event(new PasswordReset($user));
+            }
+        );
+
+        // If the password was successfully reset, we will redirect the user back to
+        // the application's home authenticated view. If there is an error we can
+        // redirect them back to where they came from with their error message.
+        return $status == Password::PASSWORD_RESET
+                    ? redirect()->route('admin.login')->with('status', __($status))
+                    : back()->withInput($request->only('email'))
+                        ->withErrors(['email' => __($status)]);
+    }
+}
diff --git a/web/html/laravel11/app/Http/Controllers/Admin/Auth/PasswordController.php b/web/html/laravel11/app/Http/Controllers/Admin/Auth/PasswordController.php
new file mode 100644
index 0000000..0a2d7a9
--- /dev/null
+++ b/web/html/laravel11/app/Http/Controllers/Admin/Auth/PasswordController.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Auth;
+
+use App\Http\Controllers\Controller;
+use Illuminate\Http\RedirectResponse;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Hash;
+use Illuminate\Validation\Rules\Password;
+
+class PasswordController extends Controller
+{
+    /**
+     * Update the user's password.
+     */
+    public function update(Request $request): RedirectResponse
+    {
+        $validated = $request->validateWithBag('updatePassword', [
+            'current_password' => ['required', 'current_password'],
+            'password' => ['required', Password::defaults(), 'confirmed'],
+        ]);
+
+        $request->user()->update([
+            'password' => Hash::make($validated['password']),
+        ]);
+
+        return back()->with('status', 'password-updated');
+    }
+}
diff --git a/web/html/laravel11/app/Http/Controllers/Admin/Auth/PasswordResetLinkController.php b/web/html/laravel11/app/Http/Controllers/Admin/Auth/PasswordResetLinkController.php
new file mode 100644
index 0000000..b7af078
--- /dev/null
+++ b/web/html/laravel11/app/Http/Controllers/Admin/Auth/PasswordResetLinkController.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Auth;
+
+use App\Http\Controllers\Controller;
+use Illuminate\Http\RedirectResponse;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Password;
+use Illuminate\View\View;
+
+class PasswordResetLinkController extends Controller
+{
+    /**
+     * Display the password reset link request view.
+     */
+    public function create(): View
+    {
+        return view('admin.auth.forgot-password');
+    }
+
+    /**
+     * Handle an incoming password reset link request.
+     *
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function store(Request $request): RedirectResponse
+    {
+        $request->validate([
+            'email' => ['required', 'email'],
+        ]);
+
+        // We will send the password reset link to this user. Once we have attempted
+        // to send the link, we will examine the response then see the message we
+        // need to show to the user. Finally, we'll send out a proper response.
+        $status = Password::sendResetLink(
+            $request->only('email')
+        );
+
+        return $status == Password::RESET_LINK_SENT
+                    ? back()->with('status', __($status))
+                    : back()->withInput($request->only('email'))
+                        ->withErrors(['email' => __($status)]);
+    }
+}
diff --git a/web/html/laravel11/app/Http/Controllers/Admin/Auth/RegisteredUserController.php b/web/html/laravel11/app/Http/Controllers/Admin/Auth/RegisteredUserController.php
new file mode 100644
index 0000000..6673b38
--- /dev/null
+++ b/web/html/laravel11/app/Http/Controllers/Admin/Auth/RegisteredUserController.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Auth;
+
+use App\Http\Controllers\Controller;
+use App\Models\Admin;
+use Illuminate\Auth\Events\Registered;
+use Illuminate\Http\RedirectResponse;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Hash;
+use Illuminate\Validation\Rules;
+use Illuminate\View\View;
+
+class RegisteredUserController extends Controller
+{
+    /**
+     * Display the registration view.
+     */
+    public function create(): View
+    {
+        return view('admin.auth.register');
+    }
+
+    /**
+     * Handle an incoming registration request.
+     *
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function store(Request $request): RedirectResponse
+    {
+        $request->validate([
+            'name' => ['required', 'string', 'max:255'],
+            'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.Admin::class],
+            'password' => ['required', 'confirmed', Rules\Password::defaults()],
+        ]);
+
+        $user = Admin::create([
+            'name' => $request->name,
+            'email' => $request->email,
+            'password' => Hash::make($request->password),
+        ]);
+
+        event(new Registered($user));
+
+        Auth::login($user);
+
+        return redirect(route('admin.dashboard', absolute: false));
+    }
+}
diff --git a/web/html/laravel11/app/Http/Controllers/Admin/Auth/VerifyEmailController.php b/web/html/laravel11/app/Http/Controllers/Admin/Auth/VerifyEmailController.php
new file mode 100644
index 0000000..f7d9c42
--- /dev/null
+++ b/web/html/laravel11/app/Http/Controllers/Admin/Auth/VerifyEmailController.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Auth;
+
+use App\Http\Controllers\Controller;
+use Illuminate\Auth\Events\Verified;
+use Illuminate\Foundation\Auth\EmailVerificationRequest;
+use Illuminate\Http\RedirectResponse;
+
+class VerifyEmailController extends Controller
+{
+    /**
+     * Mark the authenticated user's email address as verified.
+     */
+    public function __invoke(EmailVerificationRequest $request): RedirectResponse
+    {
+        if ($request->user()->hasVerifiedEmail()) {
+            return redirect()->intended(route('admin.dashboard', absolute: false).'?verified=1');
+        }
+
+        if ($request->user()->markEmailAsVerified()) {
+            event(new Verified($request->user()));
+        }
+
+        return redirect()->intended(route('dadmin.ashboard', absolute: false).'?verified=1');
+    }
+}
diff --git a/web/html/laravel11/app/Http/Requests/Auth/AdminLoginRequest.php b/web/html/laravel11/app/Http/Requests/Auth/AdminLoginRequest.php
new file mode 100644
index 0000000..200cf65
--- /dev/null
+++ b/web/html/laravel11/app/Http/Requests/Auth/AdminLoginRequest.php
@@ -0,0 +1,85 @@
+<?php
+
+namespace App\Http\Requests\Auth;
+
+use Illuminate\Auth\Events\Lockout;
+use Illuminate\Foundation\Http\FormRequest;
+use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\RateLimiter;
+use Illuminate\Support\Str;
+use Illuminate\Validation\ValidationException;
+
+class AdminLoginRequest extends FormRequest
+{
+    /**
+     * Determine if the user is authorized to make this request.
+     */
+    public function authorize(): bool
+    {
+        return true;
+    }
+
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
+     */
+    public function rules(): array
+    {
+        return [
+            'email' => ['required', 'string', 'email'],
+            'password' => ['required', 'string'],
+        ];
+    }
+
+    /**
+     * Attempt to authenticate the request's credentials.
+     *
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function authenticate(): void
+    {
+        $this->ensureIsNotRateLimited();
+
+        if (! Auth::guard('admin')->attempt($this->only('email', 'password'), $this->boolean('remember'))) {
+            RateLimiter::hit($this->throttleKey());
+
+            throw ValidationException::withMessages([
+                'email' => trans('auth.failed'),
+            ]);
+        }
+
+        RateLimiter::clear($this->throttleKey());
+    }
+
+    /**
+     * Ensure the login request is not rate limited.
+     *
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function ensureIsNotRateLimited(): void
+    {
+        if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
+            return;
+        }
+
+        event(new Lockout($this));
+
+        $seconds = RateLimiter::availableIn($this->throttleKey());
+
+        throw ValidationException::withMessages([
+            'email' => trans('auth.throttle', [
+                'seconds' => $seconds,
+                'minutes' => ceil($seconds / 60),
+            ]),
+        ]);
+    }
+
+    /**
+     * Get the rate limiting throttle key for the request.
+     */
+    public function throttleKey(): string
+    {
+        return Str::transliterate(Str::lower($this->string('email')).'|'.$this->ip());
+    }
+}
diff --git a/web/html/laravel11/app/Providers/AppServiceProvider.php b/web/html/laravel11/app/Providers/AppServiceProvider.php
index 452e6b6..85da575 100644
--- a/web/html/laravel11/app/Providers/AppServiceProvider.php
+++ b/web/html/laravel11/app/Providers/AppServiceProvider.php
@@ -3,6 +3,8 @@
 namespace App\Providers;
 
 use Illuminate\Support\ServiceProvider;
+use Illuminate\Support\Facades\Config;
+use Illuminate\Support\Facades\Request;
 
 class AppServiceProvider extends ServiceProvider
 {
@@ -19,6 +21,8 @@ public function register(): void
      */
     public function boot(): void
     {
-        //
+        if (Request::is('admin*')) {
+            Config::set('session.cookie', env('SESSION_COOKIE_ADMIN', 'laravel_admin_session'));
+        }
     }
 }
diff --git a/web/html/laravel11/bootstrap/app.php b/web/html/laravel11/bootstrap/app.php
index 7b162da..0b1d21d 100644
--- a/web/html/laravel11/bootstrap/app.php
+++ b/web/html/laravel11/bootstrap/app.php
@@ -3,15 +3,35 @@
 use Illuminate\Foundation\Application;
 use Illuminate\Foundation\Configuration\Exceptions;
 use Illuminate\Foundation\Configuration\Middleware;
+use Illuminate\Support\Facades\Route; //追加
+use Illuminate\Http\Request; //追加
+use Illuminate\Support\Facades\Auth; //追加
+// use Illuminate\Auth\Middleware\RedirectIfAuthenticated;//追加
 
 return Application::configure(basePath: dirname(__DIR__))
     ->withRouting(
-        web: __DIR__.'/../routes/web.php',
-        commands: __DIR__.'/../routes/console.php',
+        web: __DIR__ . '/../routes/web.php',
+        api: __DIR__ . '/../routes/api.php',
+        commands: __DIR__ . '/../routes/console.php',
         health: '/up',
+        then: function () {
+            Route::middleware('web')
+                // ->prefix('admin')->as('admin.')
+                ->group(base_path('routes/admin.php'));
+        },
     )
     ->withMiddleware(function (Middleware $middleware) {
-        //
+        // ゲスト(未ログイン)のリダイレクト先
+        $middleware->redirectGuestsTo(function (Request $request) {
+            return $request->is('admin*') ? route('admin.login') : route('login');
+        });
+
+        // 認証済みユーザーのリダイレクト先
+        $middleware->redirectUsersTo(function (Request $request) {
+            return $request->is('admin*')
+                ? route('admin.dashboard')   // 管理者ログイン済み時
+                : route('dashboard');        // 通常ユーザーログイン済み時
+        });
     })
     ->withExceptions(function (Exceptions $exceptions) {
         //
diff --git a/web/html/laravel11/config/auth.php b/web/html/laravel11/config/auth.php
index 0ba5d5d..bb88b29 100644
--- a/web/html/laravel11/config/auth.php
+++ b/web/html/laravel11/config/auth.php
@@ -35,13 +35,19 @@
     |
     */
 
+
     'guards' => [
         'web' => [
             'driver' => 'session',
             'provider' => 'users',
         ],
+        'admin' => [
+            'driver' => 'session',
+            'provider' => 'admins',
+        ],
     ],
 
+
     /*
     |--------------------------------------------------------------------------
     | User Providers
@@ -64,6 +70,10 @@
             'driver' => 'eloquent',
             'model' => env('AUTH_MODEL', App\Models\User::class),
         ],
+        'admins' => [
+            'driver' => 'eloquent',
+            'model' => App\Models\Admin::class,
+        ],
 
         // 'users' => [
         //     'driver' => 'database',
@@ -97,6 +107,12 @@
             'expire' => 60,
             'throttle' => 60,
         ],
+        'admins' => [
+            'provider' => 'admins',
+            'table' => 'admin_password_reset_tokens',
+            'expire' => 60,
+            'throttle' => 60,
+        ],
     ],
 
     /*
diff --git a/web/html/laravel11/database/migrations/1000_01_01_000000_create_admins_table.php b/web/html/laravel11/database/migrations/1000_01_01_000000_create_admins_table.php
index a41d08e..7c166ef 100644
--- a/web/html/laravel11/database/migrations/1000_01_01_000000_create_admins_table.php
+++ b/web/html/laravel11/database/migrations/1000_01_01_000000_create_admins_table.php
@@ -20,6 +20,12 @@ public function up(): void
             $table->rememberToken();
             $table->timestamps();
         });
+
+        Schema::create('admin_password_reset_tokens', function (Blueprint $table) {
+            $table->string('email')->primary();
+            $table->string('token');
+            $table->timestamp('created_at')->nullable();
+        });
     }
 
     /**
@@ -28,5 +34,6 @@ public function up(): void
     public function down(): void
     {
         Schema::dropIfExists('admins');
+        Schema::dropIfExists('admin_password_reset_tokens');
     }
 };
diff --git a/web/html/laravel11/database/seeders/DatabaseSeeder.php b/web/html/laravel11/database/seeders/DatabaseSeeder.php
index 0719d78..e666115 100644
--- a/web/html/laravel11/database/seeders/DatabaseSeeder.php
+++ b/web/html/laravel11/database/seeders/DatabaseSeeder.php
@@ -15,6 +15,7 @@ public function run(): void
     {
         $this->call([
             AdminSeeder::class,
+            UserSeeder::class,
         ]);
     }
 }
diff --git a/web/html/laravel11/database/seeders/UserSeeder.php b/web/html/laravel11/database/seeders/UserSeeder.php
new file mode 100644
index 0000000..98ce5f0
--- /dev/null
+++ b/web/html/laravel11/database/seeders/UserSeeder.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Database\Seeders;
+
+use Illuminate\Database\Console\Seeds\WithoutModelEvents;
+use Illuminate\Database\Seeder;
+use Illuminate\Support\Facades\Hash;
+use App\Models\User;
+
+class UserSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     */
+    public function run(): void
+    {
+        $result = [];
+        $data = [
+            ['id' => 1, 'name' => 'test ユーザー', 'email' => 't@x.jp', 'password' => Hash::make('test1234')],
+            ['id' => 2, 'name' => 'test2 ユーザー', 'email' => 't2@x.jp', 'password' => Hash::make('test1234')],
+        ];
+
+        $result = User::insertOrIgnore($data);
+
+        if (!$result) {
+            echo "\033[31mSkip!!\033[0m\n";
+        }
+    }
+}
\ No newline at end of file
diff --git a/web/html/laravel11/resources/views/admin/auth/confirm-password.blade.php b/web/html/laravel11/resources/views/admin/auth/confirm-password.blade.php
new file mode 100644
index 0000000..3d38186
--- /dev/null
+++ b/web/html/laravel11/resources/views/admin/auth/confirm-password.blade.php
@@ -0,0 +1,27 @@
+<x-guest-layout>
+    <div class="mb-4 text-sm text-gray-600">
+        {{ __('This is a secure area of the application. Please confirm your password before continuing.') }}
+    </div>
+
+    <form method="POST" action="{{ route('password.confirm') }}">
+        @csrf
+
+        <!-- Password -->
+        <div>
+            <x-input-label for="password" :value="__('Password')" />
+
+            <x-text-input id="password" class="block mt-1 w-full"
+                            type="password"
+                            name="password"
+                            required autocomplete="current-password" />
+
+            <x-input-error :messages="$errors->get('password')" class="mt-2" />
+        </div>
+
+        <div class="flex justify-end mt-4">
+            <x-primary-button>
+                {{ __('Confirm') }}
+            </x-primary-button>
+        </div>
+    </form>
+</x-guest-layout>
diff --git a/web/html/laravel11/resources/views/admin/auth/forgot-password.blade.php b/web/html/laravel11/resources/views/admin/auth/forgot-password.blade.php
new file mode 100644
index 0000000..cb32e08
--- /dev/null
+++ b/web/html/laravel11/resources/views/admin/auth/forgot-password.blade.php
@@ -0,0 +1,25 @@
+<x-guest-layout>
+    <div class="mb-4 text-sm text-gray-600">
+        {{ __('Forgot your password? No problem. Just let us know your email address and we will email you a password reset link that will allow you to choose a new one.') }}
+    </div>
+
+    <!-- Session Status -->
+    <x-auth-session-status class="mb-4" :status="session('status')" />
+
+    <form method="POST" action="{{ route('password.email') }}">
+        @csrf
+
+        <!-- Email Address -->
+        <div>
+            <x-input-label for="email" :value="__('Email')" />
+            <x-text-input id="email" class="block mt-1 w-full" type="email" name="email" :value="old('email')" required autofocus />
+            <x-input-error :messages="$errors->get('email')" class="mt-2" />
+        </div>
+
+        <div class="flex items-center justify-end mt-4">
+            <x-primary-button>
+                {{ __('Email Password Reset Link') }}
+            </x-primary-button>
+        </div>
+    </form>
+</x-guest-layout>
diff --git a/web/html/laravel11/resources/views/admin/auth/login.blade.php b/web/html/laravel11/resources/views/admin/auth/login.blade.php
new file mode 100644
index 0000000..4b6b901
--- /dev/null
+++ b/web/html/laravel11/resources/views/admin/auth/login.blade.php
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html lang="ja">
+
+<head>
+  <meta charset="utf-8">
+  <title>管理画面ログイン</title>
+</head>
+
+<body>
+
+  {{-- セッションステータス --}}
+  @if (session('status'))
+    <div>
+      {{ session('status') }}
+    </div>
+  @endif
+
+  <form method="POST" action="{{ route('admin.login') }}">
+    @csrf
+
+    {{-- Email --}}
+    <div style="margin-bottom: 1em;">
+      <label for="email">Email</label><br>
+      <input
+        type="email" id="email" name="email" value="{{ old('email') }}" required autofocus
+        style="width: 100%; padding: 0.5em;">
+      @error('email')
+        <div>
+          {{ $message }}
+        </div>
+      @enderror
+    </div>
+
+    {{-- Password --}}
+    <div style="margin-bottom: 1em;">
+      <label for="password">Password</label><br>
+      <input
+        type="password" id="password" name="password" required">
+      @error('password')
+        <div>
+          {{ $message }}
+        </div>
+      @enderror
+    </div>
+
+    {{-- Remember Me --}}
+    <div style="margin-bottom: 1em;">
+      <label>
+        <input
+          type="checkbox"
+          name="remember"
+          {{ old('remember') ? 'checked' : '' }}>
+        Remember me
+      </label>
+    </div>
+
+    {{-- Submit --}}
+    <div style="margin-bottom: 1em;">
+      <button type="submit" style="padding: 0.75em 1.5em;">
+        Log in
+      </button>
+    </div>
+
+    {{-- Forgot Password --}}
+    @if (Route::has('admin.password.request'))
+      <div>
+        <a href="{{ route('admin.password.request') }}">
+          Forgot your password?
+        </a>
+      </div>
+    @endif
+  </form>
+
+</body>
+
+</html>
diff --git a/web/html/laravel11/resources/views/admin/auth/register.blade.php b/web/html/laravel11/resources/views/admin/auth/register.blade.php
new file mode 100644
index 0000000..a857242
--- /dev/null
+++ b/web/html/laravel11/resources/views/admin/auth/register.blade.php
@@ -0,0 +1,52 @@
+<x-guest-layout>
+    <form method="POST" action="{{ route('register') }}">
+        @csrf
+
+        <!-- Name -->
+        <div>
+            <x-input-label for="name" :value="__('Name')" />
+            <x-text-input id="name" class="block mt-1 w-full" type="text" name="name" :value="old('name')" required autofocus autocomplete="name" />
+            <x-input-error :messages="$errors->get('name')" class="mt-2" />
+        </div>
+
+        <!-- Email Address -->
+        <div class="mt-4">
+            <x-input-label for="email" :value="__('Email')" />
+            <x-text-input id="email" class="block mt-1 w-full" type="email" name="email" :value="old('email')" required autocomplete="username" />
+            <x-input-error :messages="$errors->get('email')" class="mt-2" />
+        </div>
+
+        <!-- Password -->
+        <div class="mt-4">
+            <x-input-label for="password" :value="__('Password')" />
+
+            <x-text-input id="password" class="block mt-1 w-full"
+                            type="password"
+                            name="password"
+                            required autocomplete="new-password" />
+
+            <x-input-error :messages="$errors->get('password')" class="mt-2" />
+        </div>
+
+        <!-- Confirm Password -->
+        <div class="mt-4">
+            <x-input-label for="password_confirmation" :value="__('Confirm Password')" />
+
+            <x-text-input id="password_confirmation" class="block mt-1 w-full"
+                            type="password"
+                            name="password_confirmation" required autocomplete="new-password" />
+
+            <x-input-error :messages="$errors->get('password_confirmation')" class="mt-2" />
+        </div>
+
+        <div class="flex items-center justify-end mt-4">
+            <a class="underline text-sm text-gray-600 hover:text-gray-900 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" href="{{ route('login') }}">
+                {{ __('Already registered?') }}
+            </a>
+
+            <x-primary-button class="ms-4">
+                {{ __('Register') }}
+            </x-primary-button>
+        </div>
+    </form>
+</x-guest-layout>
diff --git a/web/html/laravel11/resources/views/admin/auth/reset-password.blade.php b/web/html/laravel11/resources/views/admin/auth/reset-password.blade.php
new file mode 100644
index 0000000..a6494cc
--- /dev/null
+++ b/web/html/laravel11/resources/views/admin/auth/reset-password.blade.php
@@ -0,0 +1,39 @@
+<x-guest-layout>
+    <form method="POST" action="{{ route('password.store') }}">
+        @csrf
+
+        <!-- Password Reset Token -->
+        <input type="hidden" name="token" value="{{ $request->route('token') }}">
+
+        <!-- Email Address -->
+        <div>
+            <x-input-label for="email" :value="__('Email')" />
+            <x-text-input id="email" class="block mt-1 w-full" type="email" name="email" :value="old('email', $request->email)" required autofocus autocomplete="username" />
+            <x-input-error :messages="$errors->get('email')" class="mt-2" />
+        </div>
+
+        <!-- Password -->
+        <div class="mt-4">
+            <x-input-label for="password" :value="__('Password')" />
+            <x-text-input id="password" class="block mt-1 w-full" type="password" name="password" required autocomplete="new-password" />
+            <x-input-error :messages="$errors->get('password')" class="mt-2" />
+        </div>
+
+        <!-- Confirm Password -->
+        <div class="mt-4">
+            <x-input-label for="password_confirmation" :value="__('Confirm Password')" />
+
+            <x-text-input id="password_confirmation" class="block mt-1 w-full"
+                                type="password"
+                                name="password_confirmation" required autocomplete="new-password" />
+
+            <x-input-error :messages="$errors->get('password_confirmation')" class="mt-2" />
+        </div>
+
+        <div class="flex items-center justify-end mt-4">
+            <x-primary-button>
+                {{ __('Reset Password') }}
+            </x-primary-button>
+        </div>
+    </form>
+</x-guest-layout>
diff --git a/web/html/laravel11/resources/views/admin/auth/verify-email.blade.php b/web/html/laravel11/resources/views/admin/auth/verify-email.blade.php
new file mode 100644
index 0000000..343fd80
--- /dev/null
+++ b/web/html/laravel11/resources/views/admin/auth/verify-email.blade.php
@@ -0,0 +1,31 @@
+<x-guest-layout>
+    <div class="mb-4 text-sm text-gray-600">
+        {{ __('Thanks for signing up! Before getting started, could you verify your email address by clicking on the link we just emailed to you? If you didn\'t receive the email, we will gladly send you another.') }}
+    </div>
+
+    @if (session('status') == 'verification-link-sent')
+        <div class="mb-4 font-medium text-sm text-green-600">
+            {{ __('A new verification link has been sent to the email address you provided during registration.') }}
+        </div>
+    @endif
+
+    <div class="mt-4 flex items-center justify-between">
+        <form method="POST" action="{{ route('verification.send') }}">
+            @csrf
+
+            <div>
+                <x-primary-button>
+                    {{ __('Resend Verification Email') }}
+                </x-primary-button>
+            </div>
+        </form>
+
+        <form method="POST" action="{{ route('admin.logout') }}">
+            @csrf
+
+            <button type="submit" class="underline text-sm text-gray-600 hover:text-gray-900 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
+                {{ __('Log Out') }}
+            </button>
+        </form>
+    </div>
+</x-guest-layout>
diff --git a/web/html/laravel11/resources/views/admin/dashboard.blade.php b/web/html/laravel11/resources/views/admin/dashboard.blade.php
new file mode 100644
index 0000000..66028f2
--- /dev/null
+++ b/web/html/laravel11/resources/views/admin/dashboard.blade.php
@@ -0,0 +1,17 @@
+<x-app-layout>
+    <x-slot name="header">
+        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
+            {{ __('Dashboard') }}
+        </h2>
+    </x-slot>
+
+    <div class="py-12">
+        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
+            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
+                <div class="p-6 text-gray-900">
+                    {{ __("You're logged in!") }}
+                </div>
+            </div>
+        </div>
+    </div>
+</x-app-layout>
diff --git a/web/html/laravel11/resources/views/layouts/navigation.blade.php b/web/html/laravel11/resources/views/layouts/navigation.blade.php
index c2d3a65..037a0f5 100644
--- a/web/html/laravel11/resources/views/layouts/navigation.blade.php
+++ b/web/html/laravel11/resources/views/layouts/navigation.blade.php
@@ -48,6 +48,17 @@
                                 {{ __('Log Out') }}
                             </x-dropdown-link>
                         </form>
+
+
+                        <form method="POST" action="{{ route('admin.logout') }}">
+                            @csrf
+
+                            <x-dropdown-link :href="route('admin.logout')"
+                                    onclick="event.preventDefault();
+                                                this.closest('form').submit();">
+                                {{ __('Admin Log Out') }}
+                            </x-dropdown-link>
+                        </form>
                     </x-slot>
                 </x-dropdown>
             </div>
@@ -95,6 +106,22 @@
                     </x-responsive-nav-link>
                 </form>
             </div>
+            <div class="mt-3 space-y-1">
+                <x-responsive-nav-link :href="route('profile.edit')">
+                    {{ __('Profile') }}
+                </x-responsive-nav-link>
+
+                <!-- Authentication -->
+                <form method="POST" action="{{ route('admin.logout') }}">
+                    @csrf
+
+                    <x-responsive-nav-link :href="route('admin.logout')"
+                            onclick="event.preventDefault();
+                                        this.closest('form').submit();">
+                        {{ __('Admin Log Out') }}
+                    </x-responsive-nav-link>
+                </form>
+            </div>
         </div>
     </div>
 </nav>
diff --git a/web/html/laravel11/routes/admin.php b/web/html/laravel11/routes/admin.php
new file mode 100644
index 0000000..ea490eb
--- /dev/null
+++ b/web/html/laravel11/routes/admin.php
@@ -0,0 +1,66 @@
+<?php
+
+use App\Http\Controllers\Admin\Auth\AuthenticatedSessionController;
+use App\Http\Controllers\Admin\Auth\ConfirmablePasswordController;
+use App\Http\Controllers\Admin\Auth\EmailVerificationNotificationController;
+use App\Http\Controllers\Admin\Auth\EmailVerificationPromptController;
+use App\Http\Controllers\Admin\Auth\NewPasswordController;
+use App\Http\Controllers\Admin\Auth\PasswordController;
+use App\Http\Controllers\Admin\Auth\PasswordResetLinkController;
+use App\Http\Controllers\Admin\Auth\RegisteredUserController;
+use App\Http\Controllers\Admin\Auth\VerifyEmailController;
+use Illuminate\Support\Facades\Route;
+
+
+
+Route::prefix('admin')->name('admin.')->middleware('guest:admin')->group(function () {
+// Route::prefix('admin')->name('admin.')->group(function () {
+    Route::get('register', [RegisteredUserController::class, 'create'])
+        ->name('register');
+
+    Route::post('register', [RegisteredUserController::class, 'store']);
+
+    Route::get('login', [AuthenticatedSessionController::class, 'create'])
+        ->name('login');
+
+    Route::post('login', [AuthenticatedSessionController::class, 'store']);
+
+    Route::get('forgot-password', [PasswordResetLinkController::class, 'create'])
+        ->name('password.request');
+
+    Route::post('forgot-password', [PasswordResetLinkController::class, 'store'])
+        ->name('password.email');
+
+    Route::get('reset-password/{token}', [NewPasswordController::class, 'create'])
+        ->name('password.reset');
+
+    Route::post('reset-password', [NewPasswordController::class, 'store'])
+        ->name('password.store');
+});
+
+Route::prefix('admin')->name('admin.')->middleware('auth:admin')->group(function () {
+    Route::get('dashboard', function () {
+        return view('admin.dashboard');
+    })->name('dashboard');
+
+    Route::get('verify-email', EmailVerificationPromptController::class)
+        ->name('verification.notice');
+
+    Route::get('verify-email/{id}/{hash}', VerifyEmailController::class)
+        ->middleware(['signed', 'throttle:6,1'])
+        ->name('verification.verify');
+
+    Route::post('email/verification-notification', [EmailVerificationNotificationController::class, 'store'])
+        ->middleware('throttle:6,1')
+        ->name('verification.send');
+
+    Route::get('confirm-password', [ConfirmablePasswordController::class, 'show'])
+        ->name('password.confirm');
+
+    Route::post('confirm-password', [ConfirmablePasswordController::class, 'store']);
+
+    Route::put('password', [PasswordController::class, 'update'])->name('password.update');
+
+    Route::post('logout', [AuthenticatedSessionController::class, 'destroy'])
+        ->name('logout');
+});
\ No newline at end of file
diff --git a/web/html/laravel11/routes/api.php b/web/html/laravel11/routes/api.php
new file mode 100644
index 0000000..e69de29
 docker_laravel % 

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?