DEV Community

Watheq Alshowaiter
Watheq Alshowaiter

Posted on

"Model Required Fields" package

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.

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up