ofi / laravel-auto-route
This package can make laravel to auto route
Requires
- illuminate/support: ~7|~8
Requires (Dev)
- orchestra/testbench: ~5|~6
- phpunit/phpunit: ~9.0
README
(Unofficial Package) This package can make laravel to auto route
Tested on :
- laravel 7 at March 19 2021
- Laravel 8 at March 20 2021
Table of content
Demo
We already install laravel 8 in heroku app and we install this package in version v1.4, you can visit here, and see sample.php below you can visit like this
https://ofi-laravel-auto-route.herokuapp.com/sample
https://ofi-laravel-auto-route.herokuapp.com/sample/time
Youtube video here
Installation & Sample
Installation
- Install laravel framework
- Install this package in laravel framework with
composer require ofi/laravel-auto-route
- Wait until finish
- Publish config file with
php artisan vendor:publish --provider="Ofi\Route\OfiServiceProvider" --tag=autoroute.config
- Open your routes/web.php and import this package class with
use Ofi\Route\AutoRoute;
- Add package init (see the sample) in your route file here
- Create sample.php controller in App/Http/Controllers (see controller sample below)
- (skip to step 8 when you alerady running your laravel application) now run your laravel application with serve command
- try to call
/sample
or/sample/time
or/sample/index
(see in screenshoot section below) . Is it works? if does'nt work you can open new issue here. Thanks - For other documentation you can see wiki page
Sample
web.php
See my web.php file below
<?php use Illuminate\Support\Facades\Route; use Ofi\Route\AutoRoute; /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ // Route::get('/', function () { // return view('welcome'); // }); Route::get('/otherroute', function () { var_dump("other route"); }); // put it at the bottom from other script AutoRoute::init();
sample.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; /** * We will call this controller later * using auto route */ class sample extends Controller { public function index() { var_dump('index'); } public function time() { var_dump(now()); } public function defaultMethod() { var_dump('default method'); } }
Configuration
See autoroute.php file in /yourLaravelFolder/config/autoroute.php
1. Namespace
The default namespace is App\Http\Controllers like a laravel default RouteServiceProvider here You can change with change default namespace in config file here
2. Method
The default method is index() (like a codeigniter auto route default method) will call when your request url is single request url for example
http://yourlaravelsite.com/singleRequest
http://yourlaravelsite.com/sample
is same as
http://yourlaravelsite.com/singleRequest/index
http://yourlaravelsite.com/sample/index
You can change default method with change default method in config file here
3. Allowed Http Method
See here. For example if you just only define GET in allowedHttp array, so you can visit your auto routing url in GET Method only.
Contributor
If you want to be our contributor you can open new issue and tell whats your problem, and we will fix it. Thanks
Thanks to :
@coziboy - coziboy profile here