T.A.
T.A.

Reputation: 642

Missing routes.php File in New Laravel Project

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.

I deleted the 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 the PHPStorm project folder, but again - no routes.php file.

Composer is saved here- C:\Users\myName\AppData\Roaming\Composer\vendor\bin. I used composer global required "laravel/installer" in the command prompt to install Laravel. Any ideas?

Upvotes: 57

Views: 62590

Answers (8)

Emanuel Bariki
Emanuel Bariki

Reputation: 11

Laravel 11 introduced a new application structure. Some files and folders are not added like in previous versions.

If developer wants to install an API route, developer must use artisan command such as:

php artisan install:api

It also only contain the AppServiceProvider, see the release notes about the providers: https://laravel.com/docs/11.x/releases#service-providers

It is recommended that developer must read all the notes from this release to keep up to date with the new changes. at https://laravel.com/docs/11.x/releases

Upvotes: 1

vishal pardeshi
vishal pardeshi

Reputation: 334

Laravel new version don't have routes.php

It has

  1. web.php To create web routes.

  2. api.php if you are using front (js) framework then write routes here.

  3. console.php the console.php used for console commands and interaction with commands.

Upvotes: 4

Svmy Paul
Svmy Paul

Reputation: 1

I face the same issues with Laravel v11. run command below:

php artisan install:api
 
php artisan install:broadcasting

Upvotes: 0

basitjee
basitjee

Reputation: 21

Listen

Go to

  • Project Folder Name --> 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:

api.php
console.php
web.php

For this new version, the routes for your controllers, you can write in web.php file

Upvotes: 1

Mirza Sisic
Mirza Sisic

Reputation: 2429

In version 5.6 there is no routes.php file under Http/Requests, from the docs:

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/user in your browser:

Route::get('/user', 'UserController@index');

enter image description here

Upvotes: 0

Maniruzzaman Akash
Maniruzzaman Akash

Reputation: 5025

@Geraldo has answered it well but still something more you can learn-

In Laravel newer version, old types of routes.php file has deleted.

Why removed:

From Laravel announcement, it has done to give more flexibility to the routes.

Solution:

Now there, a route folder has added and inside that folder there are 4 files.

  1. web.php -- The previous routes were in this files mainly. Here is where you can register web routes for your application.
  2. api.php -- Here is where you can register API routes for your application.
  3. channels.php -- Here you may register all of the event broadcasting channels that your application supports.
  4. console.php -- For all of the console commands and interaction with commands.

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.

Upvotes: 2

Akshay Khale
Akshay Khale

Reputation: 8371

In the Latest Laravel they have removed common routes.php where as they have added different route files to better manage your application routes.

There is

  1. 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.

  2. 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 getUsers then the API URL will be example.com/api/getUsers. The most important thing to notice is POST requests to an API url will not be validated for CSRF Token.

  3. routes/console.php : routes file where you can define your Artisan commands which you can run from Laravel Artisan CLI.

Upvotes: 12

Geraldo Novais
Geraldo Novais

Reputation: 2190

The lastest version of Laravel doesn't have a routes.php file.

This 'routes.php' file was located in \app\Http in the older versions.

In the newer version, Laravel 5.3, we have a folder named 'routes', where we can find the following files:

  • api.php
  • console.php
  • web.php

For this new version, the routes for your controllers, you can put inside web.php file

See the documentation about routing here

https://laravel.com/docs/5.3/routing#basic-routing

The video lesson you are watching may be outdated.

Upvotes: 137

Related Questions