Slamm
1 week ago

Artisan make:controller with parent option not working (Laravel 7.0)

Posted 1 week ago by Slamm

Hi all,

I've just asked myself if it is possible to create a Controller using artisan make:controller and directly say which Controller to extend. e.g. ParentController which itself extends Controller.

Using artisan make:controller --help displayed the option: --parent[=PARENT] "Generate a nested resource controller class".

I thought: awesome! that's what I've wanted - at least that's what I thought.

When using the parent option, I get the following Output: A App\ParentController model does not exist. Do you want to generate it? (yes/no).

Saying no will create a controller with the following content:

<?php

namespace App\Http\Controllers;

use App\ParentController;
use Illuminate\Http\Request;
use {{ namespacedModel }};

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

    /**
     * Show the form for creating a new resource.
     *
     * @param  \App\ParentController  $ParentController
     * @return \Illuminate\Http\Response
     */
    public function create(ParentController $ParentController)
    {
        //
    }

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

    /**
     * Display the specified resource.
     *
     * @param  \App\ParentController  $ParentController
     * @param  \{{ namespacedModel }}  ${{ modelVariable }}
     * @return \Illuminate\Http\Response
     */
    public function show(ParentController $ParentController, {{ model }} ${{ modelVariable }})
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\ParentController  $ParentController
     * @param  \{{ namespacedModel }}  ${{ modelVariable }}
     * @return \Illuminate\Http\Response
     */
    public function edit(ParentController $ParentController, {{ model }} ${{ modelVariable }})
    {
        //
    }

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

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\ParentController  $ParentController
     * @param  \{{ namespacedModel }}  ${{ modelVariable }}
     * @return \Illuminate\Http\Response
     */
    public function destroy(ParentController $ParentController, {{ model }} ${{ modelVariable }})
    {
        //
    }
}

Look broken to me. Now my question(s):

  1. Did I got this option wrong? In my understanding the --modeloption would have this behaviour.
  2. If my understanding is correct: Does anybody else have this issue? It affects Laravel 7.0.

Many thanks and kind regards

Please sign in or create an account to participate in this conversation.