Download the PHP package watheqalshowaiter/model-required-fields without Composer
On this page you can find all versions of the php package watheqalshowaiter/model-required-fields. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download watheqalshowaiter/model-required-fields
More information about watheqalshowaiter/model-required-fields
Files in watheqalshowaiter/model-required-fields
Package model-required-fields
Short Description Get the model required fields without nullables, primary keys and fields with defaults.
License MIT
Homepage https://github.com/watheqalshowaiter/model-required-fields
Informations about the package model-required-fields
Model Required Fields
Get the required model fields, excluding primary keys, nullable fields, and fields with defaults.
Installation
You can install the package via Composer:
We prefer --dev
because usually you will use it in development, not in production.
Usage
We Assume that the User
model has this schema as the defaults
-
Add the
RequiredFields
trait to your model - Now use the trait as follows
That's it!
Another Complex Table
let's say the Post
model has these fields
-
We can add the
RequiredFields
trait to thePost
Model - Now use the trait as follows
And more
We have the flexibility to get required fields with nullables, defaults, primary keys, and a mix of them or return all fields. You can use these methods with these results:
Why?
The problem
I wanted to add tests to a legacy project that didn't have any. I wanted to add tests but couldn't find a factory, so I tried building them. However, it was hard to figure out the required fields for testing the basic functionality since some tables have too many fields.
The Solution
To solve this, I created a simple trait that retrieves the required fields easily. Later, I added support for older Laravel versions, as that was where most of the use cases occurred. Eventually, I extracted it into this package.
So Briefly, This package is useful if:
- you want to build factories or tests for projects you didn't start from scratch.
- you are working with a legacy project and don't want to be faced with SQL errors when creating tables.
- you have so many fields in your table and want to get the required fields fast.
- or any use case you find it useful.
Features
✅ Supports Laravel versions: 11, 10, 9, 8, 7, and 6.
✅ Supports PHP versions: 8.2, 8.1, 8.0, and 7.4.
✅ Supports SQL databases: SQLite, MySQL/MariaDB, PostgreSQL, and SQL Server.
✅ Fully automated tested with PHPUnit.
✅ Full GitHub Action CI pipeline to format code and test against all Laravel and PHP versions.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
If you have any ideas or suggestions to improve it or fix bugs, your contribution is welcome. I encourage you to look at todos which are the most important features need to be added. If you have something different, submit an issue first to discus or report a bug, then do a pull request.
Security Vulnerabilities
If you find any security vulnerabilities don't hesitate to contact me at watheqalshowaiter[at]gmail[dot]com
to fix
them.
Credits
- Watheq Alshowaiter
- All Contributors
License
The MIT License (MIT). Please see License File for more information.