Download the PHP package joecianflone/modelproperties without Composer

On this page you can find all versions of the php package joecianflone/modelproperties. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package modelproperties

Model Properties

As a developer, you may have experienced the cognitive load of dealing with arrays to define various model behaviors in Laravel, such as fillable, guarded, casting, default values, and hidden properties. I found myself wondering if there was a more streamlined way to handle this. What if we could use PHP attributes on the class itself to define these properties? This idea led me to explore this approach, which I share in this video

Support Me

Buy me a coffee or something, but more importantly would be if you used this and like it, if you'd talk about this and also tell me if you have any issues with it.

Installation

Usage

Here's a standard User model where you've got some fillable fields and a few casts and whatnot:

Again, my gripe here is that it takes a bit of work to understand all the fields this model has. It's pretty easy to miss that the id is a string if you were looking quickly...and oh crap, I forgot to turn off auto-incrementing did you catch that? How about the fact that the password should be cast and I forgot that one too

So using the model properties it would now look like this:

That's it. Add the HasModelProperties trait and you're good to start using the ModelProperties attribute and have a better DX.

Config Settings

Model properties has a few configurations you can change and they're publishable.

Mass Assignment

Turn this off at your own risk! By default, this will set $guarded = ['*'] you should leave it this way.

Default Mass Assignment Mode

Now if you don't want to set all your properties to either guareded or fillable on all your models you can change this to be either 'guarded' or 'fillable' and then you don't have to worry about being explicit.

NOTE: with mass_assignment_protection turned on, you really never have to expliclty set something to guarded they'll really be discarded because $guarded = ['*']. If you DO turn off mass_assignment_protection you're going to NEED to set this to guarded or else we'll throw an exception with this set to either 'none' or 'fillable'.

Honestly, think twice before doing that. Your best bet here is to leave mass_assignment_protection set to true and, if anything, set this to fillable. That's basically Laravel's default behavior and setting all the props over to the fillable array.

Explicitly Cast Strings

In the above examples, see how how told the model that some properties were strings? You don't actually need to cast strings as strings in laravel, but some people like doing that, so if you'd like to be explicit, set this to true.

How it works

Under the hood, we're not doing too many fancy things. At the end of the day, the attribute will get transformed into a PHP object and we "just use" all the standard Laravel model variables to populate fillable, guarded and whatever else. The only magic here, if there is any, is Laravels own built-in ability to automatically execute a method in a trait.

So what is this doing? Mostly parsing the attributes and dumping them in the right places. It adds no extra cruft to the model and if you were to dd() a model that uses ModelProperties and a model that does not, you'd see no difference in the object created.

Testing

This plugin uses Pest for our Unit and Architecture tests, if you'd like to run them yourself you can use...

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of modelproperties with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
crell/attributeutils Version ^1.2.0
illuminate/config Version ^11.0|^12.0
illuminate/contracts Version ^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package joecianflone/modelproperties contains the following files

Loading the files please wait ...