Support the ongoing development of Laravel.io →
posted 9 years ago
Requests
Last updated 2 years ago.
0

anyone?

Why does everything have to be static?

0

The answer is in the error message: you're trying to use $this when in a static context, wich is not allowed.

To set/get data in models, you can use "default" methods, there's no need to declare them static.

Behind the scenes, Laravel will instantiate the class and call the desired methods, so it isn't "everything static".

Edit: another way is by getting/setting data directly in attributes. In your example, $foo is a public attribute, so you can do something like this:

$object = new Foo;
$object->foo = 'Hello!';
echo $object->foo;
Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.