laravel-ide-helper icon indicating copy to clipboard operation
laravel-ide-helper copied to clipboard

Non-static method 'where'... after update Laravel and Ide-helper

Open morawcik opened this issue 3 years ago • 5 comments

  • ide-helper Version: 2.9.1
  • Laravel Version: 8.33.1
  • PHP Version: 8.0

Hi, today after updated Laravel from 8.31.0 to 8.33.1 and Ide-helper from 2.9.0 to 2.9.1 (by composer update) and running all commands (eloquent, generate, meta and models --write-mixin) i'm getting error

Non-static method 'where' should not be called statically, but the class has the '__magic' method.

for User::where('email', $email)->first()

morawcik avatar Mar 20 '21 15:03 morawcik

Can you provide a repository for easily reproducing this? and can you provide the exact command you used there?

Ideally something like:

  • composer create-project laravel/laravel laravel-ide-helper-issue-1191
  • commit
  • make you changes
  • commit
  • push and show it here

mfn avatar Mar 20 '21 19:03 mfn

Ok. I created fresh install (couple of times to check it) https://github.com/morawcik/test-laravel-ide-helper and it seams that sth with ide-generate:eloquent. My steps:

  • run composer create-project laravel/laravel laravel-ide-helper-issue-1191
  • create database/database.sqlite file and update .env for this
  • add User::where('email', '[email protected]')->first(); to default route in routes/web.php
  • install laravel ide-helper
  • run php artisan vendor:publish --provider="Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider" --tag=config
  • run php artisan ide-helper:model -M
  • run php artisan ide-helper:generate
  • here everything works fine, command+click (or windows+click) points to where in _ide_helper.php
  • run php artisan ide-helper:eloquent
  • here i go Non-static method 'where' should not be called statically, but the class has the '__magic' method. and command+click points to where in vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php

morawcik avatar Mar 20 '21 20:03 morawcik

Ok I see, I think I initially missed the you use ide-helper:eloquent. IMHO that's quite a bastard comment and should be avoided, as it modifies your vendor files 😢

However, cloning your project I still don't know where I should get this

Non-static method 'where' should not be called statically, but the class has the '__magic' method

I can confirm the CDM-click gives 2 options to me now: image

But this is expected in this setup I would say 🤷‍♀️

Trying to avoid writing the meta data of the models to them brings all this weird issues it seems to me.

mfn avatar Apr 01 '21 19:04 mfn

I'm also getting this issue when using --write-mixin. Is there a solution?

CitizenBeta avatar Dec 27 '21 18:12 CitizenBeta

I get this issue aswell. Have it on all my Eloquent models when calling create or so:

image

iwasherefirst2 avatar Nov 11 '22 06:11 iwasherefirst2