2

In Laravel Framework one can use Model's Methods as Static and also Non-static, For example you can get a user from Databse like this:

User::where('id', 1)->first();

and also like this:

$user = new User();
$user->where('id', 1)->first();

how can you do this in PHP? because as far as i know a method can only be Static or Non-Static but not both.

0

1 Answer 1

8

This is being done via the magic method __callStatic which is creating a new instance of the model then calling the method on it. This particular method, where, doesn't exist on the model and is being handled by the magic method __call which is calling this method on an Eloquent Builder instance.

PHP.net Manual - OOP - Overloading __callStatic __call

Laravel - Github - Eloquent Model __callStatic

Laravel - Github - Eloquent Model __call

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

1 Comment

methods are methods, properties are properties (i assume property is what you are meaning by 'attribute')... also the term "attribute(s)" has special meaning in terms of Eloquent models

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.