Hello guys, In this tutorial we will how to configure Laravel Auto Routes package and how it work. Laravel auto route package generate automatically all your controller method into GET method route. you need to define one line Route::auto(‘/test’, ‘TestController’); code on your web.php then it will ready to used directly all controller method as get routes.
All routes you will found affter test/you_controller_method. let see the example below.
First we need to install laravel in our machine. If you wanna learn how to install laravel application check this link: How to install laravel and configure.
after the laravel installation, we need to install the Laravel Auto Routes packack. open your terminal and run the below command.
composer require izniburak/laravel-auto-routes
This package service provider laravel automatically discover by the help of laravel auto discovery package so here we no need manually added it.
Next we need to add config file into the laravel. run the below command in terminal.
php artisan vendor:publish --provider="Buki\AutoRoute\AutoRouteServiceProvider"
After that we need to create a controller. let create a controller by artisan command.
php artisan make:controller ProductsController
Now open your ProductsController.php file and then add some method.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class ProductsController extends Controller { public function index() { echo "index method"; dd(); } public function add_product() { echo "add products method"; dd(); } public function all_product() { echo "all products method"; dd(); } }
After that, we need to define one route into our web.php file.
Route::auto('/products', 'ProductsController'); # OR Route::auto('/products', ProductsController::class);
You can specify HTTP Method for the method of the Controllers. If you want that a method works with GET
method and other method works with POST
method, you can do it. Just add a prefix for the method.
now start your serve with the help of bellow command.
php artisan serve
That it. now we available auto route feature in our project. let run some routes into our web browser.
