Laravel 11 Create Custom Route File Example

Laravel 11 Create Custom Route File Example

In Laravel 11, the process of creating a custom routes file and configuring it in the application has changed. But it has become easier than even older versions of Laravel.

In this easy and short guide, we will show you how to create a custom route file and use it in laravel 11 application with example.

Steps on How to Create Custom Route File in Laravel 11

Here are steps:

Step 1: Create a Custom Route File

Go to routes folder and make custom route file named teacher.php.

After that add the following test route in teacher.php file; something like this:

<?php

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
return "welcome to teacher route";
});

Step 2: Add Route Files to App.php

Open app.php file from bootstrap folder and add or register your custom routes file in it; something like this:

    ->withRouting(
web: __DIR__ . '/../routes/web.php',
commands: __DIR__ . '/../routes/console.php',
health: '/up',
then: function () {
Route::namespace('Teacher')->prefix('teacher')->name('teacher.')->group(base_path('routes/teacher.php'));
},
)

Step 3: Use Custom Routes

Now you can define your routes in custom teacher.php route file and use it as follows:

http://localhost:8000/teacher/* 

Conclusion

This is simple and short guide on how to create and use custom route file in Laravel 11 application.

If you know or want more information about Custom Routing in Laravel 11 version, you can check out https://laravel.com/docs/11.x/routing#routing-customization.

Recommended Guides

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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