Illuminate\Database\Eloquent\Model::__unset PHP Method

__unset() public method

Unset an attribute on the model.
public __unset ( string $key ) : void
$key string
return void
    public function __unset($key)
    {
        unset($this->attributes[$key], $this->relations[$key]);
    }

Usage Example

Example #1
0
	/**
	 * Fill a model with input data
	 *
	 * @param \Illuminate\Database\Eloquent\Model	$model
	 * @param mixed									$input
	 *
	 * @return array
	 */
	public function fillModel(&$model, $input)
	{
		$input = $input ? explode(',', $input) : array();
		$fieldName = $this->getOption('field_name');
		$relationship = $model->{$fieldName}();

		//if this field is sortable, delete all the old records and insert the new ones one at a time
		if ($sortField = $this->getOption('sort_field'))
		{
			//first delete all the old records
			$relationship->delete();

			//then re-attach them in the correct order
			foreach ($input as $i => $item)
			{
				$relationship->attach($item, array($sortField => $i));
			}
		}
		else
		{
			//elsewise the order doesn't matter, so use sync
			$relationship->sync($input);
		}

		//unset the attribute on the model
		$model->__unset($fieldName);
	}
All Usage Examples Of Illuminate\Database\Eloquent\Model::__unset
Model