Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Creates --api flag during make:controller to exclude #create and #edit methods #22920

Closed
wants to merge 3 commits into from

Conversation

OzairP
Copy link
Contributor

@OzairP OzairP commented Jan 25, 2018

An optional flag --api is added to the make:controller command which will not generate #create and #edit methods which are not used for API requests.

This is referenced in the Laravel docs under the Controllers section titled API Resource Routes which registers resources without #create #edit.

https://laravel.com/docs/5.5/controllers#resource-controllers

@OzairP OzairP changed the title Creates --api flag during make:controller to exclude #create and #edit methods [5.6] Creates --api flag during make:controller to exclude #create and #edit methods Jan 25, 2018
@carusogabriel
Copy link
Contributor

Similar to #21865

@KKSzymanowski
Copy link
Contributor

KKSzymanowski commented Jan 25, 2018

I like this idea.

Couple of issues though:
First of all, it doesn't seem to work:
I did:

  1. Install Laravel 5.6
laravel new test --dev
  1. Point to the fork in composer.json
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/ozairp/framework"
    }
],
  1. composer update
  2. Make sure composer pulled in your fork
  3. Run
php artisan make:controller FooController --api

Result: controller is empty

  1. Run
php artisan make:controller FooController --resource --api

Result: controller contains create and edit methods.

Second, this code:

$stub = null;

if ($this->option('parent')) {
    return __DIR__.'/stubs/controller.nested.stub';
} elseif ($this->option('model')) {
    return __DIR__.'/stubs/controller.model.stub';
} elseif ($this->option('resource')) {
    return __DIR__.'/stubs/controller.stub';
}

if ($this->option('api') && $stub !== null) {
    $stub = substr_replace($stub, '.api', -5, 0);
}

If I'm not mistaken, in the condition of the last if, the $stub variable is always null. Didn't you mean to set the $stub in the if-elseif blocks instead of returning?

Next, php artisan make:controller --help shows

...
  -a, --api[=API]        Generate a api resource controller class.
...

It seems like --api can accept an argument. What would be the argument?
Didn't you mean to declare it as

['api', 'a', InputOption::VALUE_NONE, 'Generate a api resource controller class.'],

instead of

['api', 'a', InputOption::VALUE_OPTIONAL, 'Generate a api resource controller class.'],

Last, I think, since the feature is backwards compatible, you can do the PR to the 5.5 branch.

P.S. Why are you naming your commits in the third person?😄

@taylorotwell
Copy link
Member

I am closing this pull request because it lacks sufficient explanation, tests, or both. It is difficult for us to merge pull requests without these things because the change may introduce breaking changes to the framework.

Feel free to re-submit your change with a thorough explanation of the feature and tests - integration tests are preferred over unit tests. Please include it's benefit to end users; the reasons it does not break any existing features; how it makes building web applications easier, etc.

Thanks!

@taylorotwell
Copy link
Member

Closing since apparently broken.

@OzairP
Copy link
Contributor Author

OzairP commented Jan 26, 2018

@taylorotwell @KKSzymanowski Thanks for the feedback, first PR to laravel/framework and pretty new to OOS! I'll resubmit the PR with your critiques in mind.

@KKSzymanowski
Copy link
Contributor

There's a free lesson at Laracasts showing how to prepare a PR(https://laracasts.com/series/how-do-i/episodes/20).

From 4:55 Jeffrey talks about how to pull in your own fork instead of Laravel Framework to test if your changes work. It might be helpful for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants