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

php artisan make:controller is wrong when creating a singleton controller with a model #52967

Open
Barbapapazes opened this issue Sep 28, 2024 · 4 comments

Comments

@Barbapapazes
Copy link

Laravel Version

11.9

PHP Version

8.2

Database Driver & Version

Sqlite

Description

Hello 👋,

The command php artisan make:controller is wrong when creating a singleton controller with a model.

If you type php artisan make:controller, then UserController, Singleton and choose the User model, you'll have the following file:

<?php

namespace App\Http\Controllers;

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

class UserController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     */
    public function show(User $user)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(User $user)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, User $user)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(User $user)
    {
        //
    }
}

If you type php artisan make:controlelr, then UserController, Singleton and do not choose a model, you'll have the following file:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class User extends Controller
{
    /**
     * Show the form for creating the resource.
     */
    public function create(): never
    {
        abort(404);
    }

    /**
     * Store the newly created resource in storage.
     */
    public function store(Request $request): never
    {
        abort(404);
    }

    /**
     * Display the resource.
     */
    public function show()
    {
        //
    }

    /**
     * Show the form for editing the resource.
     */
    public function edit()
    {
        //
    }

    /**
     * Update the resource in storage.
     */
    public function update(Request $request)
    {
        //
    }

    /**
     * Remove the resource from storage.
     */
    public function destroy(): never
    {
        abort(404);
    }
}

As you can see, only the second one is a singleton.

Steps To Reproduce

  1. Create a new project
  2. Try to create a singleton controller with artisan (php artisan make:controller -> UserController -> singleton -> User)
  3. Observe the generate file, it's not the correct one
Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@vjaykoogu
Copy link

@Barbapapazes looks good to me, What output you are expecting in File ?

@Barbapapazes
Copy link
Author

@Barbapapazes looks good to me, What output you are expecting in File ?

I'm expected the same that when I don't choose a model but maybe I'm wrong. 🤷‍♂️

@vjaykoogu
Copy link

@Barbapapazes i dont think so, what if we don't need Model ? The existing flow looks good to me.

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

No branches or pull requests

3 participants