Skip to content

Inspections

David Rodrigues edited this page Jun 1, 2017 · 11 revisions

Column without annotation

This inspection tells that you should declares the @property annotation on class that refers to each database columns. It is useful to determine the column type, getting a better IDE code support.

This inspection affects only models that extends the Eloquent\Model class, direct or indirectly.

Features

  • Check for id column annotation;
  • Check for columns annotations from class properties: $casts and $dates;
  • Check for columns annotations from accessors and mutators methods;
  • Check for columns annotations from relationships methods;
  • Check for columns annotations from model instance references (eg. $user->name);
  • Check for created_at and updated_at when the property $timestamps = true;
  • Check for deleted_at column when using the SoftDeletes trait;
  • Quick-fix available;

Auto type-guessing

From 0.2.0 release, this inspection will try to guess the type based on some conditions:

  • For id (or $primaryKey) column, always will be int (except if other type defined on $keyType);
  • For any column suffixed _id consider as int;
  • For any column suffixed _at consider as \Carbon\Carbon;
  • For accessors, try to guess from the return type;
  • For mutators, try to guess from accessor return type, if it exists;
  • For any column declared on $casts property, consider the cast type (eg. => "int", then int, see supported casts at Laravel docs);
  • For any other case, will consider mixed;
Clone this wiki locally