新 Laravel 项目中缺少 routes.php 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39313536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Missing routes.php File in New Laravel Project
提问by T.A.
I downloaded Composer, installed Laravel, and started my first Laravel project to begin learning Laravel using the lessons on laracast (great lessons). Lesson two covers routes. My new project does not have a routes.php file.
我下载了 Composer,安装了 Laravel,并开始了我的第一个 Laravel 项目,开始使用 laracast 上的课程学习 Laravel(很棒的课程)。第二课介绍路线。我的新项目没有 routes.php 文件。
I deleted composer and started again. Same thing. Tried two different computers. Same thing. I was using NetBeans so I tried using PHP Storm. Same thing. I tried making my own routes.php file but it doesn't seem to work right because I know nothing about Laravel at this point. I tried creating and saving the project in htdocs, and then PHPStorm project folder, again - no routes.php file.
我删除了作曲家并重新开始。一样。试了两台不同的电脑。一样。我使用的是 NetBeans,所以我尝试使用 PHP Storm。一样。我尝试制作自己的 routes.php 文件,但它似乎无法正常工作,因为此时我对 Laravel 一无所知。我尝试在 htdocs 中创建并保存项目,然后在 PHPStorm 项目文件夹中再次创建 - 没有 routes.php 文件。
Composer is saved here- C:\Users\myName\AppData\Roaming\Composer\vendor\bin. I used composer global require "laravel/installer" in command prompt to install laravel. Any ideas?
Composer 保存在这里 - C:\Users\myName\AppData\Roaming\Composer\vendor\bin。我在命令提示符下使用 composer global require "laravel/installer" 来安装 laravel。有任何想法吗?
回答by Geraldo Novais
The lastest version of Laravel doesn't have a routes.php file.
最新版本的 Laravel 没有 routes.php 文件。
This 'routes.php' file was located in \app\Http in the older versions.
这个 'routes.php' 文件在旧版本中位于 \app\Http 中。
In the newer version, Laravel 5.3, we have a folder named 'routes', where we can find the following files:
在较新的 Laravel 5.3 版本中,我们有一个名为“routes”的文件夹,我们可以在其中找到以下文件:
- api.php
- console.php
- web.php
- api.php
- 控制台.php
- 网页.php
For this new version, the routes for your controllers, you can put inside web.php file
对于这个新版本,你的控制器的路由,你可以放在 web.php 文件中
See the documentation about routing here
在此处查看有关路由的文档
https://laravel.com/docs/5.3/routing#basic-routing
https://laravel.com/docs/5.3/routing#basic-routing
The video lesson you are watching may be outdated.
您正在观看的视频课程可能已过时。
回答by Akshay Khale
In the Latest Laravel they have removed common routes.php where as they have added different route files to better manage your application routes.
在最新的 Laravel 中,他们删除了 common routes.php,因为他们添加了不同的路由文件以更好地管理您的应用程序路由。
There is
有
routes/web.php: routes file which works similar to routes.php file where you can have your routes and all the POST routes in web.php file will be validated for the CSRF Token similar to normal Laravel Post route.
routes/api.php: routes file where you can have your Application's API routes, the URL will be example.com/api/Eg. If you have route getUsersthen the API URL will be example.com/api/getUsers. The most important thing to notice is POSTrequests to an API url will not be validated for CSRF Token.
routes/console.php: routes file where you can define your Artisan commands which you can run from Laravel Artisan CLI.
routes/web.php:路由文件,它的工作方式类似于routes.php文件,您可以在其中设置路由,并且 web.php 文件中的所有 POST 路由都将针对类似于普通 Laravel Post 路由的 CSRF 令牌进行验证。
routes/api.php: 路由文件,您可以在其中拥有应用程序的 API 路由,URL 将是example.com/api/例如。如果你有路由getUsers那么 API URL 将是example.com/api/getUsers。需要注意的最重要的事情是对 API url 的POST请求将不会针对CSRF Token进行验证。
routes/console.php:路由文件,您可以在其中定义可以从 Laravel Artisan CLI 运行的 Artisan 命令。
回答by vishal pardeshi
Laravel new version don't have routes.php
Laravel 新版本没有 routes.php
Ithas
它有
1.web.php To create Web routes
1.web.php 创建Web路由
2.api.php if you are using front (js) framework then write routes here
2.api.php 如果你使用的是前端(js)框架,那么在这里写路由
3.console.php the console.php used for console commands and interaction with commands
3.console.php 用于控制台命令和与命令交互的console.php
回答by Maniruzzaman Akash
@Geraldo has answered it well but still something more you can learn-
@Geraldo 回答得很好,但您还可以学到更多东西-
In Laravel newer version, old types of routes.php file has deleted.
在 Laravel 新版本中,旧类型的 routes.php 文件已被删除。
Why removed:
为什么删除:
From Laravel announcement, it has done to give more flexibility to the routes.
从 Laravel 公告开始,它已经为路由提供了更大的灵活性。
Solution:
解决方案:
Now there, a route folder has added and inside that folder there are 4 files.
现在,添加了一个路由文件夹,该文件夹内有 4 个文件。
web.php
-- The previous routes were in this files mainly. Here is where you can register web routes for your application.api.php
-- Here is where you can register API routes for your application.channels.php
-- Here you may register all of the event broadcasting channels that your application supports.console.php
-- For all of the console commands and interaction with commands.
web.php
-- 以前的路由主要在这个文件中。您可以在此处为您的应用程序注册 Web 路由。api.php
-- 您可以在此处为您的应用程序注册 API 路由。channels.php
-- 在这里您可以注册您的应用程序支持的所有事件广播频道。console.php
-- 用于所有控制台命令和与命令的交互。
See, now it is more flexible for you to add any API and then link it via it's api.php
route file and normal route in web.php
file. Thanks.
看,现在你可以更灵活地添加任何 API,然后通过它的api.php
路由文件和文件中的正常路由链接它web.php
。谢谢。
回答by basitjee
Listen
听
Go to
去
- Project Folder Name --> app --> Http --> routes.php
- 项目文件夹名称 --> app --> Http --> routes.php
You will find routes there.
你会在那里找到路线。
In the newer version, Laravel 5.3, find folder named 'routes', where following files are present:
在较新的Laravel 5.3版本中,找到名为“routes”的文件夹,其中存在以下文件:
api.php
console.php
web.php
For this new version, the routes for your controllers, you can write in web.php file
对于这个新版本,你的控制器的路由,你可以写在 web.php 文件中
回答by Mirza Sisic
In version 5.6 there is no routes.php file under Http/Requests, from the docs:
在 5.6 版中,Http/Requests 下没有 routes.php 文件,来自文档:
All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by the framework. The routes/web.php file defines routes that are for your web interface. These routes are assigned the web middleware group, which provides features like session state and CSRF protection. The routes in routes/api.php are stateless and are assigned the api middleware group.
For most applications, you will begin by defining routes in your routes/web.php file. The routes defined in routes/web.php may be accessed by entering the defined route's URL in your browser. For example, you may access the following route by navigating to http://your-app.test/userin your browser:
Route::get('/user', 'UserController@index');
所有 Laravel 路由都在路由文件中定义,这些文件位于 routes 目录中。这些文件由框架自动加载。routes/web.php 文件定义了用于您的 Web 界面的路由。这些路由被分配到 web 中间件组,它提供了会话状态和 CSRF 保护等功能。routes/api.php 中的路由是无状态的,并被分配到 api 中间件组。
对于大多数应用程序,您将从在 routes/web.php 文件中定义路由开始。可以通过在浏览器中输入定义的路由的 URL 来访问在 routes/web.php 中定义的路由。例如,您可以通过在浏览器中导航到http://your-app.test/user来访问以下路由 :
Route::get('/user', 'UserController@index');