Model Helper

This helper will provide information about specific model, which can be loaded from full classname ModelHelper::fromClass() or from an model's file ModelHelper::fromFile().

Model Helper is "macroable" and "collectable", which allows you to run batch methods and collect output with ModelHelper::fromClass('App\User')->collect('name', 'namespace')

Construct from File

/**
 * Load a model from file
 * @param string $path
 * @return Model
 */

ModelHelper::fromFile(): void

Construct from Class

/**
 * Load a model from class
 * @param string $class
 * @return Model
 */

ModelHelper::fromClass(): void

Reflection

/**
 * Get class reflection
 * @return ReflectionClass
 * @throws \ReflectionException
 */

ModelHelper::reflection(): void

Parent

/**
 * Get immediate parent of a model class
 * Note that this might not be useful as user can extend from custom 'model' class not Laravel one.
 * @return string
 */

ModelHelper::parent(): void

Class

/**
 * Get model's class (namespace + name)
 * @return string
 */

ModelHelper::class(): void

Name

/**
 * Get model's name without namespace
 * @return string
 */

ModelHelper::name(): void

Namespace

/**
 * Get models's namespace
 * @return string
 */

ModelHelper::namespace(): void

Instance

/**
 * Initiate a new instance of a model
 * @return Eloquent
 */

ModelHelper::instance(): void

Primary

/**
 * Get primary key for a model
 * @return string
 */

ModelHelper::primary(): void

Table

/**
 * Get model's table
 * @return string
 */

ModelHelper::table(): void

Hidden

/**
 * Get hidden attributes
 * @return Collection
 */

ModelHelper::hidden(): void

Fillable

/**
 * Get fillable attributes
 * @return Collection
 */

ModelHelper::fillable(): void

Request

/**
 * Get FormRequest for this model if one exists
 * @return null|FormRequest
 */

ModelHelper::fillable(): void

Attributes

/**
 * Get model's attributes
 * @return Collection
 */

ModelHelper::attributes(): void

Rules

/**
 * Build validation rules
 * @param bool $fillableOnly: true
 * @param bool $deepAnalysis: false
 * @return Collection
 */

ModelHelper::rules(): void

Relationships

/**
 * Get model's relationships
 * @return Collection
 */

ModelHelper::relationships(): void

Fields

/**
 * Get attribute and relationship fields (either native HTML or Vue extended)
 * This method basically maps attribute type to corresponding field/input type.
 * @param bool $fillable: default false
 * @param bool $extended: default false
 * @return Collection
 */

ModelHelper::fields(): void