shlogg · Early preview
David Duymelinck @xwero

Revamping Eloquent Model Class For PHP 8.4

Rewriting Eloquent Model class for PHP 8.4: Moving properties to attributes, using property hooks & attributes for metadata & serialization. What changes do you want to see?

A part of the The problem with indirections post was about the behaviour of the Eloquent Model class. This got me thinking, what if it was rewritten with PHP 8.4 as a minimum requirement.

  
  
  The fields

  
  
  Now

At the moment it is not required to add the fields as a property to get the values from the database.
For mass assignment you need the protected fillable property. But there is also a protected guarded property, which is the opposite of the fillable attribute.
The default value can be added with the protected attributes property.
The relations are always functions.
And also a...