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

is() public method

Determine if two models have the same ID and belong to the same table.
public is ( Model $model ) : boolean
$model Model
return boolean
    public function is(Model $model)
    {
        return $this->getKey() === $model->getKey() && $this->getTable() === $model->getTable() && $this->getConnectionName() === $model->getConnectionName();
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Checks to see if the $arg is instantiated and the same instance of this obj.
  * Ridiculous this is not built in...
  *** NOTE! As of Laravel 5.3, it finally is - but we want to return the model instance
  * @param any $var
  * $return boolean|static - false if not instantiated or not the same object, else the object
  */
 public function is(Model $var = null)
 {
     if (!$var || !$var instanceof Model) {
         return false;
     }
     if (method_exists(get_parent_class(), 'is')) {
         if (!parent::is($var)) {
             return false;
         }
     }
     if (!static::instantiated($var) || !static::instantiated($this)) {
         return false;
     }
     if (get_class($this) !== get_class($var)) {
         return false;
     }
     if ($this->getKey() !== $var->getKey()) {
         return false;
     }
     return $this;
 }
Model