Laraship

⌘K
  1. Home
  2. Docs
  3. Laraship
  4. Customize Laraship
  5. Properties Column

Properties Column

Objects can have properties column which is a JSON of values to store additional attributes, it’s highly recommended to use this field whenever you have additional meta to the objects.

To Add Attributes support to the Model you need to add the ModelPropertiesTrait to the model, there are already many models utilizing this trait so you can use them as an example.

also, don’t forget to add the properties column to your migration file

$table->text('properties')->nullable();

 

here are the available functions for the Properties column:

 

/**
 * @return mixed
 */
public function getProperties()


/**
 * @param $key
 * @return bool
 */
public function hasProperty($key)


/**
 * @param $key
 * @param null $default
 * @param null $castTo
 * @return mixed|null
 *
 * The Php casts allowed are:
 *
 * (int), (integer) - cast to integer
 * (bool), (boolean) - cast to boolean
 * (float), (double), (real) - cast to float
 * (string) - cast to string
 * (array) - cast to array
 * (object) - cast to object
 * (unset) - cast to NULL
 */
public function getProperty($key, $default = null, $castTo = null)


/**
 * @param $key
 * @param $value
 * @return mixed
 */
public function setProperty($key, $value)


/**
 * @param $key
 * @return mixed
 */
public function forgetProperty($key)

/**
 * @return mixed
 */
public function purgeProperties()

/**
 * @param $properties
 * @return mixed
 */
public function setProperties($properties)