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

[6.x] Controller stub from make:model --api missing model typehint #31222

Merged
merged 1 commit into from
Jan 24, 2020

Conversation

crynobone
Copy link
Member

@crynobone crynobone commented Jan 24, 2020

Discovered based on code replication orchestral/canvas@dc4fd9f

@deligoez
Copy link
Contributor

I'm not sure this is necessary, maybe just the opposite, this is the intended behavior.

If you want a resource API controller you simply type

php artisan make:model ModelName --api --resource

or if you don't want to resource a resource controller, only an API controller

php artisan make:model ModelName --api

@crynobone
Copy link
Member Author

crynobone commented Jan 24, 2020

@deligoez The only different between the two is just whether you have Model $model or $id. That's not the meaning of --resource, using --api --resource here conflict with each other.

Current Behaviour

php artisan make:model Foo --api
<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class FooController 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  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

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

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
php artisan make:model Foo --api --resource
<?php

namespace App\Http\Controllers;

use App\Foo;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class FooController 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\Foo  $foo
     * @return \Illuminate\Http\Response
     */
    public function show(Foo $foo)
    {
        //
    }

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

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

Expected Behaviour

--api option is essentially the same with --resource but without create() or edit() since it isn't applicable for API request. There shouldn't be any reason to do --resource here.

@taylorotwell taylorotwell merged commit 6f59618 into laravel:6.x Jan 24, 2020
@crynobone crynobone deleted the patch-2 branch February 4, 2021 07:37
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.

3 participants