Skip to content

Methods such as orderBy, inRandomOrder, paginate, findOrFail etc. do not appear from Model #55867

Closed

Description

@IArnaut2

Laravel Version

12.14.1

PHP Version

8.4.0

Database Driver & Version

No response

Description

I was watching this tutorial. https://www.youtube.com/playlist?list=PL4cUxeGkcC9gF5Gez17eHcDIxrpVSBuVt

I have written this Ninja model:

class Ninja extends Model
{
    protected $fillable = [
        "name",
        "skill",
        "bio",
        // 19 Handling Post Requests
        "dojo_id"
    ];
    /** @use HasFactory<\Database\Factories\NinjaFactory> */
    use HasFactory;

    // 17 Foreign Keys 2
    public function dojo()
    {
        return $this->belongsTo(Dojo::class);
    }
}

But when I type it's methods, methods orderBy, findOrFail and paginate aren't recognizable in Laravel 12. They do not get suggestions in VS Code. I've checked Model class and these methods don't exist in it. I have the official Laravel extension and PHP Intelephense installed. I assume something has changed in Laravel 12.
Image
Image

I've found a workaround to add method query after the Model name. It works for paginate, findOrFail, but it doesn't work for orderBy, inRandomOrder etc.

public function index()
{
    // route --> /ninjas/
    // 15 Pagination
    $ninjas = Ninja::with("dojo")->orderBy("created_at", "desc")->paginate(10);
    return view("ninjas.index", [
        "ninjas" => $ninjas
    ]);
}

Steps To Reproduce

  1. Create Laravel Project
  2. Create a Ninja model (with flags -mfs)
  3. Create a Ninja controller for the model
  4. Type $ninja = Ninja:: in the controller
  5. Type a method name, e.g. orderBy
  6. It does not appear in suggestions

Activity

  1. robert-moore96 commented on May 27, 2025

    @robert-moore96

    what happens if you ignore VS Code and actually try to run the code?

    i feel like this is really just an issue with intellisense rather than that the methods actually dont exist

    laravel historically hasnt played very nicely with IDEs and while there have been several plugins etc attempting to improve that that seems the most likely explanation to me here

  2. macropay-solutions commented on May 27, 2025

    @macropay-solutions

    Model forwards call to protected Eloquent Builder $query when the function is not found in model. You can use https://github.com/barryvdh/laravel-ide-helper for better autocomplete.
    We always use Model::query()->... to have autocomplete and ctrl+click functionality.

  3. IArnaut2 commented on May 28, 2025

    @IArnaut2
    Author

    what happens if you ignore VS Code and actually try to run the code?

    i feel like this is really just an issue with intellisense rather than that the methods actually dont exist

    laravel historically hasnt played very nicely with IDEs and while there have been several plugins etc attempting to improve that that seems the most likely explanation to me here

    The project has no problem when running.

  4. jaysindarov commented on May 29, 2025

    @jaysindarov

    what happens if you ignore VS Code and actually try to run the code?
    i feel like this is really just an issue with intellisense rather than that the methods actually dont exist
    laravel historically hasnt played very nicely with IDEs and while there have been several plugins etc attempting to improve that that seems the most likely explanation to me here

    The project has no problem when running.

    Then you don't have to worry about this problem but I suggest you to use another IDE maybe phpstorm would be better option or I don't usually use VS Code and since you are getting this error maybe you need to configure it a bit.

  5. IArnaut2 commented on Jun 2, 2025

    @IArnaut2
    Author

    what happens if you ignore VS Code and actually try to run the code?
    i feel like this is really just an issue with intellisense rather than that the methods actually dont exist
    laravel historically hasnt played very nicely with IDEs and while there have been several plugins etc attempting to improve that that seems the most likely explanation to me here

    The project has no problem when running.

    Then you don't have to worry about this problem but I suggest you to use another IDE maybe phpstorm would be better option or I don't usually use VS Code and since you are getting this error maybe you need to configure it a bit.

    I'm broke for PHPStorm.

  6. macropay-solutions commented on Jun 2, 2025

    @macropay-solutions

    @IgorArnaut this does not work for vs code? #55867 (comment)

  7. IArnaut2 commented on Jun 2, 2025

    @IArnaut2
    Author

    VSCode might not come as optimized for PHP development, but its extensions can improve DevEx significantly:

    * [`laravel.vscode-laravel` (Official Laravel VSCode extension)](https://marketplace.visualstudio.com/items?itemName=laravel.vscode-laravel)
    

    I already have that extension.

    * [`bmewburn.vscode-intelephense-client` (PHP Intelephense)](https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client)
    

    This one too.

    * [`ValeryanM.vscode-phpsab` (PHP Sniffer & Beautifier)](https://marketplace.visualstudio.com/items?itemName=ValeryanM.vscode-phpsab)
    
    * [`mohamedbenhida.laravel-intellisense` (Laravel Intellisense)](https://marketplace.visualstudio.com/items?itemName=mohamedbenhida.laravel-intellisense)
    
    * [`amiralizadeh9480.laravel-extra-intellisense` (Laravel Extra Intellisense)](https://marketplace.visualstudio.com/items?itemName=amiralizadeh9480.laravel-extra-intellisense)
    

    And this one too.

  8. IArnaut2 commented on Jun 2, 2025

    @IArnaut2
    Author

    @IgorArnaut this does not work for vs code? #55867 (comment)

    orderBy DOES NOT APPEAR.

    2025-06-02.16-53-31.mp4
  9. danielsum commented on Jun 5, 2025

    @danielsum

    You can use https://github.com/barryvdh/laravel-ide-helper and the Model::query() method for autocomplete. Phpstorm or Cursor have a better auto completion IMHO

  10. ghabriel25 commented on Jun 6, 2025

    @ghabriel25
    Contributor

    @IgorArnaut

    Image

  11. IArnaut2 commented on Jun 6, 2025

    @IArnaut2
    Author

    @IgorArnaut

    Image

    And? It works for you, doesn't work for me.

  12. locked and limited conversation to collaborators on Aug 27, 2025
  13. converted this issue into a discussion #56780 on Aug 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions