😄Create Custom Route File, route frontend, route backend? (ok)
https://www.itsolutionstuff.com/post/how-to-create-custom-route-file-in-laravelexample.html
1. Ví dụ đã hoàn thành 👍
C:\xampp\htdocs\reset\app\Providers\RouteServiceProvider.php (Bản gốc 8.x)
<?php
namespace App\Providers;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider {
/**
* The path to the "home" route for your application.
*
* This is used by Laravel authentication to redirect users after login.
*
* @var string
*/
public const HOME = '/home';
/**
* The controller namespace for the application.
*
* When present, controller route declarations will automatically be prefixed with this namespace.
*
* @var string|null
*/
// protected $namespace = 'App\\Http\\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot() {
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
});
}
/**
* Configure the rate limiters for the application.
*
* @return void
*/
protected function configureRateLimiting() {
RateLimiter::for ('api', function (Request $request) {
return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
});
}
}C:\xampp\htdocs\reset\app\Providers\RouteServiceProvider.php
C:\xampp\htdocs\reset\routes\admin.php
C:\xampp\htdocs\reset\routes\web.php
C:\xampp\htdocs\reset\routes\manager.php
2. Ví dụ đã hoàn thành 👍

C:\xampp82\htdocs\lva6\app\Providers\RouteServiceProvider.php
C:\xampp82\htdocs\lva6\routes\admin.php
C:\xampp82\htdocs\lva6\app\Http\Controllers\Admin\MediaLibraryController.php

How to Create Custom Route File in Laravel?
By Hardik Savani June 22, 2020 Category : LaravelPauseUnmuteLoaded: 2.45%Fullscreen
In this tutorial, i will show you laravel create custom route file example. you can understand a concept of laravel add custom route file example. step by step explain how to add custom route file in laravel. i explained simply about how to create custom route file in laravel. You just need to some step to done define custom route file in laravel 6, laravel 7, laravel 8 and laravel 9.
If you are working with large application in laravel and you have different types of users then you have to create custom route file for user type wise in your application. for example if you have user, manager and admin three types of user then you have different prefix like "user/*", "manager/*" and "admin/*" url will be. so if you create different route file then you can easily make it better way your routes.
In this example, i will let you know how you to create custom route file in laravel application. you can easily use it with laravel 5, laravel 6 and laravel 7. So let's follow bellow steps:
In this tutorial, I am going to share with you how to define and use subdomain routes better way in Laravel 5 application.
Step 1 : Install Laravel Fresh Application
we are going from scratch, So we require to get fresh Laravel application using bellow command, So open your terminal OR command prompt and run bellow command:
Step 2: Create Custom Route File
Here, we will create following route file with bellow listed route. so let's create route file.
1) User Routes : Here you have to define routes in web.php in routes folder. in that file you have declare routes for user login.
2) Manager Routes : Here you have to create new file manager.php in routes folder. in that file you have declare routes for manager user.
3) Admin Routes : Here you have to create new file admin.php in routes folder. in that file you have declare routes for admin user.
So, let's proceed with routes define:
routes/web.php
routes/manager.php
routes/admin.php
Read Also: Laravel clear cache from route, view, config and all cache data from application
Step 3: Add Files to ServiceProvider
In this step, we require to register our new two user file in RouteServiceProvider, that way we can create new file for each user wise like we create two user "admin" and "manager" then we create new file admin.php and manager.php in routes directory for define routing.
So, let's open RouteServiceProvider.php and put bellow code:
app/Providers/RouteServiceProvider.php
Read Also: Laravel Disable Registration Route Example
Ok, now we are ready to run simple example with our users. So, in this tutorial i explained i created following url as listed bellow:
1) http://localhost:8000/
2) http://localhost:8000/manager/*
3) http://localhost:8000/admin/*
I hope it can help you.
Last updated
Was this helpful?