Last active
October 19, 2022 03:35
-
-
Save bogordesaincom/62b9f17064db9fd1a64bde6fcfc3a847 to your computer and use it in GitHub Desktop.
Sanctum Api Token
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Route::group(['middleware' => ['auth:sanctum']], function () { | |
| // Product Group | |
| Route::apiResource('brands', BrandsController::class); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| return [ | |
| 'paths' => ['api/*'], | |
| 'allowed_methods' => ['*'], | |
| 'allowed_origins' => ['https://frontend.test', 'http://localhost:3000'], | |
| 'allowed_origins_patterns' => [], | |
| 'allowed_headers' => ['*'], | |
| 'exposed_headers' => [], | |
| 'max_age' => 0, | |
| 'supports_credentials' => false, | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'api' => [ | |
| // ini dicomment | |
| // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, | |
| 'throttle:api', | |
| \Spatie\ResponseCache\Middlewares\CacheResponse::class, | |
| \Illuminate\Routing\Middleware\SubstituteBindings::class, | |
| ], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function store(LoginRequest $request): JsonResponse | |
| { | |
| if (! Auth::attempt($request->only('email', 'password'))) { | |
| return responder()->error('unauthenticated')->respond(); | |
| } | |
| $user = User::where('email', $request['email'])->firstOrFail(); | |
| $token = $user->createToken('auth_token')->plainTextToken; | |
| return responder()->success(['token' => $token])->respond(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment