<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
watheqalshowaiter / model-required-fields example snippets
Schema::create('users', function (Blueprint $table) {
$table->id(); // primary key
$table->string('name'); // e
$table->string('password'); //
// Facade way
use WatheqAlshowaiter\ModelRequiredFields\ModelFields;
use App\Models\User;
ModelFields::model(User::class)->getRequiredFields(); // returns ['name', 'email', 'password']
// Macro way
User::getRequiredFields(); // returns ['name', 'email', 'password']
Schema::create('posts', function (Blueprint $table) {
$table->uuid('id')->primary(); // primary key
$table->foreignId('user_id')->constrained(); // llable(); // nullable (but will be changed later) 👇
$table->boolean('active')->default(false); // default
$table->string('title'); // ble){
$table->json('description')->nullable(false)->change(); //
// Facade way
ModelFields::model(Post::class)->getRequiredFields(); // returns ['user_id', 'ulid', 'title', 'description']
// Macro way
Post::getRequiredFields(); // returns ['user_id', 'ulid', 'title', 'description']
// The default parameters only )
->getRequiredFields(
$withNullables = false,
$withDefaults = false,
$withPrimaryKey = false
);
// or
ModelFields::model(Post::class)->getRequiredFields();
// returns ['user_id', 'ulid', 'title', 'description']