Giter Club home page Giter Club logo

laravel-routes-publisher's Introduction

Laravel Routes Publisher

A command to replace deprecated Route::controller() and Route::controllers() with explicit routes.

what it does

In laravel 5.3 implicit controller routes will be removed from the framework, the functionality will likely be extracted into a separate package, however if you'd like to make the move and start using explicit routes this package will help you.

Installation

Step 1:

composer require themsaid/laravel-routes-publisher

Step 2:

Include the following command in your $commands attribute of app/Console/Kernel.php:

\Themsaid\RoutesPublisher\RoutesPublisherCommand::class

Usage

Run the following command:

php artisan themsaid:publishRoutes

After the command is done, two new files will be generated in your app/Http directory:

routes.php.generated
routes.php.backup

Replace the content of your routes.php file with that of routes.php.generated, knowing that if anything went wrong a backup of your original routes.php's content will be available in routes.php.backup.

This package assumes the following:

  • Your routes.php doesn't contain any PHP syntax errors.
  • Your routes.php file is located in app\Http\routes.php with the exact name.
  • Your routes.php files doesn't include any other file using include or require.
  • Your Application namespace is correctly registered in the psr-4 section of composer.json.

Problems?

I tried hard to cover different syntax and file formatting in this package, however if you found any problems while using the package please open a new issue.

laravel-routes-publisher's People

Contributors

insign avatar omranic avatar themsaid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

laravel-routes-publisher's Issues

Erorr

E:\OSPanel\domains\laravelCurs.md>php artisan themsaid:publishRoutes

ErrorException : file_get_contents(E:\OSPanel\domains\laravelCurs.md\app\Http/routes.php): failed to open stream: No such file or directory

at E:\OSPanel\domains\laravelCurs.md\vendor\themsaid\laravel-routes-publisher\src\RoutesPublisherCommand.php:53
49| * @return mixed
50| */
51| public function handle()
52| {

53| $exactFileContent = file_get_contents(app_path('Http/routes.php'));
54|
55| $preparedFileContent = $this->prepareFileContent($exactFileContent);
56|
57| $output = '';

Exception trace:

1 file_get_contents("E:\OSPanel\domains\laravelCurs.md\app\Http/routes.php")
E:\OSPanel\domains\laravelCurs.md\vendor\themsaid\laravel-routes-publisher\src\RoutesPublisherCommand.php:53

2 Themsaid\RoutesPublisher\RoutesPublisherCommand::handle()
E:\OSPanel\domains\laravelCurs.md\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:29

Please use the argument -v to see more details.

E:\OSPanel\domains\laravelCurs.md>

Step 2 command doesn't work for Laravel 5.2

protected $commands = [
    '\Themsaid\RoutesPublisher\RoutesPublisherCommand::class'
];

However, the following does:

protected $commands = [
    'Themsaid\RoutesPublisher\RoutesPublisherCommand'
];

Shall I create a PR for the README.md with this caveat for Laravel 5.2?

php7 reflectionmethod

is the ReflectionParameter::hasType only available on php7? maybe you should hint that in describion

Route::any not converted

As the title says, functions in my controller that start with any do not get put into the generated routes file using Route::any()

wrong route folder address

the below warning will shown when i want to convert my controller to routes .
i'm using laravel 5.3 .
should i install this package on my oldest laravel project ?
file_get_contents(D:\projects\codedesign\app\Http/routes.php): failed to open stream: No such file or directory

Doesn't parsed method parameters with strict type

Example controller method:

public function getEdit( int $id ) {
   # ...
}

Parsing result:

Route::get('access/users/edit', 'Access\UsersController@getEdit');

When it should be:

Route::get('access/users/edit/{id}', 'Access\UsersController@getEdit');

Route namespace looks at wrong class path

It seems that the command does not work correctly if I have a group with a namespace. For example:

Route::group(['prefix' => 'acme', 'namespace' => 'Acme'], function () {
    Route::controller('abc', 'AbcController');
}

This throws the error:

  [ReflectionException]                                 
  Class App\Http\Controllers\AbcController does not exist

However, it should be looking at App\Http\Controllers\Acme\AbcController, which does exist. If I change my routes to:

Route::group(['prefix' => 'acme', 'namespace' => 'Acme'], function () {
    Route::controller('abc', 'Acme\AbcController');
}

then it works, so I have a workaround, but this means changing all my routes to include the namespace and then presumably fixing them after running the command.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.