Skip to content
Advertisement

api versioning page not found

I’m trying to create my 1st API on Laravel 8, and want to create versioning that would look like this

JavaScript

My user controller looks like this

JavaScript

in my config/app.php i have this

'api_latest' => '1',

in my middleware (appHttpMiddlewareAPIVersion.php)

JavaScript

in my kernal (app/http/kernel.php)

JavaScript

in my /app/Providers/RouteServiceProvider.php

JavaScript

and in my routes/api_v1.php i have this

JavaScript

I’m getting a 404 error when i type this in the browser https://domain/api/v1/users and how do i return a json error instead of a html page for this route?

UPDATE

php artisan route:list gives me this

JavaScript

Advertisement

Answer

ok, do not uses middleware for changes url, only working with the routes, proof with this.

frist you must install passport or sanctum, in my case I have used passport. See the documentation continue with the installation

in app/Providers/RouteServiceProvider.php

JavaScript

In routes/api/v1/api.php

JavaScript

In app/Http/Controller/Auth/LoginController

to see the client’s IP is like this $request->ip();

JavaScript

In app/Http/Controller/UserController

JavaScript

In routes/api/v1/api.php

if you look. I have used middleware so only authenticated users can see content.

JavaScript

I hope this information helps you.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement