使用Composer安装Laravel后routes目录缺失问题求助
routes Directory in Your Laravel Installation Hey there! Since you're coming from CodeIgniter, Laravel's directory structure might feel a bit different at first—let's get that missing routes directory sorted out.
First, let's check the most common reason for this: Laravel version differences. Starting with Laravel 11, the framework simplified its directory structure, and the routes folder is now located inside the app directory (app/routes) instead of the project root. If you installed the latest version but were looking at documentation for Laravel 10 or older, that's exactly why you didn't see it in the root!
To confirm your Laravel version, navigate into your project folder in CMD and run:
php artisan --version
If you're running Laravel 11:
Just head over to app/routes—you'll find all your route files there (like web.php, api.php) right where they should be. This is the new default structure, so the docs you were looking at might be outdated.
If you're running Laravel 10 or earlier but still missing the root routes directory:
This is likely due to a partial or interrupted installation. Try these steps:
- Delete the existing project folder: In CMD, run
rmdir /s laravel(Windows) orrm -rf laravel(Mac/Linux) to remove the incomplete installation. - Clear Composer's cache: Run
composer clear-cacheto make sure you're pulling fresh files. - Re-run the installation command:
Make sure your internet connection stays stable during the install—interruptions can cause missing files.composer create-project --prefer-dist laravel/laravel laravel
If re-installing still doesn't work:
You can manually create the routes directory in your project root and add the default route files. For example:
- Create
routes/web.phpwith this basic content:<?php use Illuminate\Support\Facades\Route; Route::get('/', function () { return view('welcome'); }); - You can grab the other default route files (
api.php,console.php,channels.php) from the official Laravel repository's matching version branch to keep things consistent.
Since you know CodeIgniter, think of this like how CodeIgniter keeps routes in application/config/routes.php—Laravel just organizes them in a dedicated folder, with separate files for web, API, and console routes to keep things clean.
内容的提问来源于stack exchange,提问作者Supun Abesekara

