0

PHPStan has found hundreds of errors in the Laravel project. Mostly, Access to an undefined property Illuminate\Database\Eloquent\Model::$id. for constructs like

$project_id = $checkpoint->project->id;

Does PHPStan not understand the relationships between Laravel models? (larastan is also installed)

Do I really need to rewrite everything to

$project_id = $checkpoint->project->id ?? null; 

(then PHPStan doesn't complain).

I tried to overcome this error through PHPDoc, but even more changes would have to be made to the code here.

1
  • Using the ide helper might work for you (it's called "IDE" helper but it auto-generates PHPDoc so PHPStan should be able to read that as well). Commented Jun 3, 2023 at 6:31

1 Answer 1

0

create MyModel class extending base Model class and use it for your inheritance. In this class you can typehint properties that commonly used in your tables like "it", "created_at"...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.