Laravel url method post not point to project folder?

Viewed 603

why my laravel url not working when method is post example the url api must be : http://localhost/PROJECTNAME/api/loginWeb

but when i click post button it always direct to http://localhost/api/loginWeb

but when method is get this okay. i use xampp

here is my htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

1 Answers

When we're using session based laravel setup, all the route generator functions(url(), route()) use hostname http://localhost as root url, not http://localhost/PROJECTNAME. To resolve this issue please do following changes in laravel app.

  • Define APP_URL in .env file as APP_URL="http://localhost/PROJECTNAME"
  • Go to RouteServiceProvider which is located at app/Providers/RouteServiceProvider and force laravel to use APP_URL as root url for your app.
public function boot()
{
    parent::boot();
    // Add following lines to force laravel to use APP_URL as root url for the app.
    $strBaseURL = $this->app['url'];
    $strBaseURL->forceRootUrl(config('app.url'));
}

Same issue occurred to me when I used same domain and a suburl to identify different projects.

Related