flipboxstudio / lumen-generator

A Lumen Generator You Are Missing
https://packagist.org/packages/flipbox/lumen-generator
MIT License
822 stars 126 forks source link

Fix and upgrade the make controller command #74

Closed jorgemudry closed 4 years ago

jorgemudry commented 4 years ago

What does this Pull Request Do?

It fixes the issue #73

It also adds the option --force to overwrite an existing controller.

How should this be manually tested?

  1. Clone the repo from my fork:
git clone https://github.com/jorgemudry/lumen-generator.git;
git checkout fix_make_controller_command;
  1. Change the name property in the composer.json file:
"name": "jorgemudry/lumen-generator",
  1. In a new lumen project, add set up the local repository to the package in your composer.json:
    "repositories": {
        "dev-package": {
            "type": "path",
            "url": "../lumen-generator",
            "options": {
                "symlink": true
            }
        }
    }
  1. Add the package to your project:
composer require jorgemudry/lumen-generator
  1. Inside of your bootstrap/app.php add this:
$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);
  1. Execute the command to create a new API controller with model binding:
php artisan make:controller ApiController --api -m User
  1. You should end up with a new ApiController.php inside of you app\Http\Controllers folder looking like this:
<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

class ApiController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\User  $user
     * @return \Illuminate\Http\Response
     */
    public function show(User $user)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\User  $user
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, User $user)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\User  $user
     * @return \Illuminate\Http\Response
     */
    public function destroy(User $user)
    {
        //
    }
}

Any background context you want to provide?

I know that model binding is not supported by Lumen out of the box, but you could easily add that functionality installing a library.

Any extra info?

happy

joelhy commented 4 years ago

When fixing bugs or adding new features, your can use branch to test your work:

https://getcomposer.org/doc/05-repositories.md#loading-a-package-from-a-vcs-repository

All you have to do is add your fork as a repository and update the version constraint to point to your custom branch. In composer.json, you should prefix your custom branch name with "dev-".

This is an example: [joelhy/composer.json] (https://gist.github.com/joelhy/1588ed9fb67473197f8cd69d2b4587cd)