ofi/laravel-auto-route

This package can make laravel to auto route

v1.7 2021-04-06 04:22 UTC

This package is auto-updated.

Last update: 2024-06-06 11:01:45 UTC


README

(Unofficial Package) This package can make laravel to auto route

Tested on :

  1. laravel 7 at March 19 2021
  2. Laravel 8 at March 20 2021

Hits

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

  1. https://www.youtube.com/watch?v=OM6fz1ZGF6U

Installation & Sample

Installation

  1. Install laravel framework
  2. Install this package in laravel framework with composer require ofi/laravel-auto-route
  3. Wait until finish
  4. Publish config file with php artisan vendor:publish --provider="Ofi\Route\OfiServiceProvider" --tag=autoroute.config
  5. Open your routes/web.php and import this package class with use Ofi\Route\AutoRoute;
  6. Add package init (see the sample) in your route file here
  7. Create sample.php controller in App/Http/Controllers (see controller sample below)
  8. (skip to step 8 when you alerady running your laravel application) now run your laravel application with serve command
  9. 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
  10. 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

Screenshoot

image

image