-
composer.json
Open in GitHub{ // "require": { "php": "^7.3|^8.0", // "laravel/sanctum": "^2.11" }, // }
-
routes/api.php
Open in GitHubuse Illuminate\Http\Request; use Illuminate\Support\Facades\Route; Route::middleware('auth:sanctum')->group(function () { Route::get('/user', function (Request $request) { return request()->user(); }); });
-
app/Http/Kernel.php
Open in GitHubuse Illuminate\Foundation\Http\Kernel as HttpKernel; class Kernel extends HttpKernel { // protected $middlewareGroups = [ // 'api' => [ \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, // ], ]; // }
-
app/Http/Controllers/Auth/AuthenticatedSessionController.php
Open in GitHubuse App\Http\Controllers\Controller; use App\Http\Requests\Auth\LoginRequest; use App\Providers\RouteServiceProvider; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; class AuthenticatedSessionController extends Controller { // public function store(LoginRequest $request) { $request->authenticate(); $request->session()->regenerate(); if (!request()->wantsJson()) { return redirect()->intended(RouteServiceProvider::HOME); } } public function destroy(Request $request) { Auth::guard('web')->logout(); $request->session()->invalidate(); $request->session()->regenerateToken(); if (!request()->wantsJson()) { return redirect('/'); } } }