laravel – can not change base URL in Docker + Laravel PHP + Nginx

We Are Going To Discuss About laravel – can not change base URL in Docker + Laravel PHP + Nginx. So lets Start this Laravel Article.

laravel – can not change base URL in Docker + Laravel PHP + Nginx

How to solve laravel – can not change base URL in Docker + Laravel PHP + Nginx

The APP_URL doesn’t really have anything to do with setting the base URL for the actual routes, it is only for setting the base URL that the route helpers append to. What you’re looking for instead is a route prefix. One thing to note before we get into this code though YOU NEED TO BE SURE YOU ARE ALWAYS USING ROUTE HELPERS TO DEFINE ROUTES, FORM ACTIONS, BASICALLY ANYTHING THAT INTERACTS WITH A URL. Otherwise you will have to remember to add the public to the path everywhere.
Open up your Route Service Provider in app/Providers/RouteServiceProvider
look for the map() function and add the route prefix
Route::prefix('public')->group(function () { $this->mapApiRoutes(); $this->mapWebRoutes(); });
that’s it. Now any route that is mapped by the route service provider will have the public/ prefix applied.
My source for this is just an extrapolation of the documentation for how to add a prefix to any route group https://laravel.com/docs/9.x/routing#route-group-prefixes

laravel – can not change base URL in Docker + Laravel PHP + Nginx

The APP_URL doesn’t really have anything to do with setting the base URL for the actual routes, it is only for setting the base URL that the route helpers append to. What you’re looking for instead is a route prefix. One thing to note before we get into this code though YOU NEED TO BE SURE YOU ARE ALWAYS USING ROUTE HELPERS TO DEFINE ROUTES, FORM ACTIONS, BASICALLY ANYTHING THAT INTERACTS WITH A URL. Otherwise you will have to remember to add the public to the path everywhere.
Open up your Route Service Provider in app/Providers/RouteServiceProvider
look for the map() function and add the route prefix
Route::prefix('public')->group(function () { $this->mapApiRoutes(); $this->mapWebRoutes(); });
that’s it. Now any route that is mapped by the route service provider will have the public/ prefix applied.
My source for this is just an extrapolation of the documentation for how to add a prefix to any route group https://laravel.com/docs/9.x/routing#route-group-prefixes

Solution 1

The APP_URL doesn’t really have anything to do with setting the base URL for the actual routes, it is only for setting the base URL that the route helpers append to. What you’re looking for instead is a route prefix. One thing to note before we get into this code though YOU NEED TO BE SURE YOU ARE ALWAYS USING ROUTE HELPERS TO DEFINE ROUTES, FORM ACTIONS, BASICALLY ANYTHING THAT INTERACTS WITH A URL. Otherwise you will have to remember to add the public to the path everywhere.

Open up your Route Service Provider in app/Providers/RouteServiceProvider

look for the map() function and add the route prefix

Route::prefix('public')->group(function () {
        $this->mapApiRoutes();

        $this->mapWebRoutes();
});

that’s it. Now any route that is mapped by the route service provider will have the public/ prefix applied.

My source for this is just an extrapolation of the documentation for how to add a prefix to any route group https://laravel.com/docs/9.x/routing#route-group-prefixes

Original Author Alec Joy Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment