This content originally appeared on DEV Community and was authored by Watheq Alshowaiter
With Model Required Fields package, you can get the required model fields, excluding primary keys, nullable fields, and fields with defaults.
I first needed this information while working on a large project with no tests or factories and many migrations. It was distracting to manually look for each required field.
I created a simple trait to fetch required fields. It was easy in Laravel 11 and 10. Then I realized that most programmers who face this problem are usually using older versions, so I added support for Laravel 9, 8, 7, and 6, and extracted the logic into a package.
I tested the code for each supported Laravel version and each SQL database: SQLite, MySQL, MariaDB, PostgreSQL, and Microsoft SQL Server. I needed to add support for each SQL database because I used the DB facade with raw SQL queries, and there were slight differences each time.
The package is fully tested with PHPUnit and GitHub Actions for every Laravel version and for each database.
The usage and examples are in the readme file.
I hope you like this package, and I welcome any contributions or comments.
package link:
https://github.com/watheqAlshowaiter/model-required-fields.
This content originally appeared on DEV Community and was authored by Watheq Alshowaiter
Watheq Alshowaiter | Sciencx (2024-07-27T11:54:35+00:00) “Model Required Fields” package. Retrieved from https://www.scien.cx/2024/07/27/model-required-fields-package/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.