Nasrul Hazim Bin Mohamad

Laravel: Artisan Extended – make:route

Dec
14

Assalamualaikum,

Yesterday, I’ve shared ideas on how to manage your Laravel’s route in Laravel: Managing Routes post.

Today, I want to share with you guys how to create easily the resourceful route, with or without prefix (yes, you can make route version too!).

First thing first, let’s create a new Laravel project and require the Artisan Extended package to your Laravel Project.

Once you’re done with installation of Artisan Extended package, you may run now in terminal the following commands:

php artisan make:route Post

This will create a new Routes directory in your app folder, and a file named Post.php(app/Routes/Post.php), and you will have \App\Routes\Post::routes(); in your routes/web.php. You may run php artisan route:list to check the route created just now.

Now, let say you want to add prefix to your route:

php artisan make:route -p v1 Post

Then, you will have \App\Routes\V1\Post::routes(); in your routes/web.php

How about I want a prefix of V1, but I want to differentiate between admin and normal user? Here how you can do it:

php artisan make:route -p v1 Admin/User && php artisan make:route -p v1 User

Now you should have \App\Routes\V1\Admin\User::routes(); and \App\Routes\V1\User::routes(); in your routes/web.php.

That’s it. It’s easy now to manage your routes.

All your routes will be store in app/Routes directory from now on and you just need to update your route files manually in case you need some extra routes in the class.

Here are some other tricks you may use:

php artisan make:route -m web,auth -p v1 Post

This will create a route in app/Routes/V1/Post.php and having middlewares of web & auth in routes/web.php

php artisan make:route -m auth:api,jwt -p v1 -a Post

This will create a route in app/Routes/API/V1/Post.php and having middlewares of auth:api & jwt in routes/api.php

Please take note that, the make:route is intended for resourceful route.

There’s some other useful Artisan commands available in Artisan Extended package, you may want to read here.

More test & result:

Create Routes

Create Routes

The Routes Structure

The Routes Structure Generated

Resourceful Controllers Automatically Created If Not Exist

Resourceful Controllers Automatically Created If Not Exist

Routes for Web

Routes for Web

Routes for API

Routes for API

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

4 + 13 =