Hello Devs,
In this tutorial, we are going to learn how to create Custom laravel route file
Follow this step by step guide given below:
Step:1
app/providers/RouteServiceProvider.php
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
$this->mapCustomerRoutes();
$this->mapUserRoutes();
}
Step:2
app/providers/RouteServiceProvider.php
/**
* Define the "user" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapUserRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/user.php'));
}
/**
* Define the "customer" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapCustomerRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/customer.php'));
}
Step:3
routes/user.php
/**
* These routes are typically stateless.
*
* @return void
*/
Route::get('user', function () {
return view('userWelcome');
});
routes/customer.php
/**
* These routes are typically stateless.
*
* @return void
*/
Route::get('customer', function () {
return view('customerWelcome');
});
Step:4
resources/view/userWelcome.blade.php
<!DOCTYPE html>
<html>
<head>
<title>User Welcome - rathorji.in</title>
</head>
<style type="text/css">
h1{
font-size: 45px;
text-align: center;
margin:5% 25%;
border:2px solid black;
width: 50%;
border-radius: 10px;
}
</style>
<body>
<h1>User Welcome</h1>
</body>
</html>
resources/view/customerWelcome.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Customer Welcome - rathorji.in</title>
</head>
<style type="text/css">
h1{
font-size: 45px;
text-align: center;
margin:5% 25%;
border:2px solid black;
width: 50%;
border-radius: 10px;
}
</style>
<body>
<h1>Customer Welcome</h1>
</body>
</html>
Run this command:
php artisan serve
Open this URL:
http://localhost:8000/users
http://localhost:8000/customer
I hope this example helps you.