You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel-nWdart Login模块创建后地址栏访问报错求助

Fixing the 404 Error for Your nWidart Laravel Login Module

Hey there, let's troubleshoot that "page not found" error when accessing /login for your newly created nWidart module. Here are the most common fixes to try, in order:

1. Verify Your Module is Activated

First, make sure your Login module is registered and enabled in your Laravel app:

  • Open config/modules.php and check if there's an entry for 'Login' => true (this should be added automatically when you run module:make, but sometimes it might not stick).
  • If it's missing, run this command to enable the module:
    php artisan module:enable Login
    

2. Check Module Route Configuration

nWidart modules have their own route files, so you need to define the /login route in the module's routes directory:

  • Navigate to Modules/Login/routes/web.php
  • Add a route pointing to your module's controller (create the controller first if you haven't):
    // Example route for a basic login page
    Route::get('/login', [\Modules\Login\Http\Controllers\LoginController::class, 'showLoginForm'])->name('login');
    
  • If you don't have a LoginController yet, generate one with:
    php artisan module:make-controller LoginController Login
    
    Make sure the controller's namespace is correct (namespace Modules\Login\Http\Controllers;) and it has the showLoginForm method (or whatever method you're routing to).

3. Clear Route & Configuration Caches

Laravel caches routes and config to speed things up, which can prevent new module routes from being detected:

  • Run these commands to clear all relevant caches:
    php artisan route:clear
    php artisan config:clear
    php artisan view:clear
    
  • After clearing, restart your server (php artisan serve again) to ensure the new routes are loaded.

4. Validate Server Rewrite Rules

If you're using Apache, ensure your public/.htaccess file exists and has the correct Laravel rewrite rules (this is usually included by default, but sometimes gets corrupted):

Example .htaccess content for Apache:

<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]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
  • If you're using Nginx, confirm your server block includes this line to handle Laravel's URL routing:
    try_files $uri $uri/ /index.php?$query_string;
    

5. Double-Check File Structure & Namespaces

Make sure all your module files are in the correct locations and have proper namespaces:

  • Controller file should be at Modules/Login/Http/Controllers/LoginController.php
  • The controller's namespace must be namespace Modules\Login\Http\Controllers;
  • Any views you reference should be in Modules/Login/Resources/views/

After going through these steps, your /login route should load correctly. If you're still hitting a 404, double-check the route list by running php artisan route:list—look for your /login entry to confirm it's registered.

内容的提问来源于stack exchange,提问作者DolDurma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:54:13