Make a new ability for a specific model.

@param  \Illuminate\Database\Eloquent\Model|string  $model
@param  string|array  $attributes
@return static
559807
public static function makeForModel($model, $attributes)
    {
        if (is_string($attributes)) {
            $attributes = ['name' => $attributes];
        }

        if ($model === '*') {
            return (new static)->forceFill($attributes + [
                'entity_type' => '*',
            ]);
        }

        if (is_string($model)) {
            $model = new $model;
        }

        return (new static)->forceFill($attributes + [
            'entity_type' => $model->getMorphClass(),
            'entity_id'   => $model->exists ? $model->getKey() : null,
        ]);
    }
773229
public static function create(array $attributes = [])
    {
        $className = get_called_class();
        /** @var ModelInterface $model */
        $model = new $className($attributes);
        $model->setIsNewRecord(false);

        return $model;
    }
738319
private function create($model)
    {
        $attrs = $this->getMutableAttributes($model);
        $this->db
            ->connect()
            ->insert($this->table, array_keys($attrs))
            ->execute(array_values($attrs));
        $model->{$this->key} = $this->db->lastInsertId();
    }
1077962
public function fill(Identifiable $model, array $attributes)
    {

        $model = $this->checkTypeAndReturn($model);
        $changed = false;

        foreach ($attributes as $key=>$value) {
            // Check for exact comparison
            if(isset($model[$key]) && $model[$key] === $value) {
                continue;
            }
            $model[$key] = $value;
            $changed = true;
        }
        return $changed;
    }
352334
public function model(Entity $model, $url, array $attributes = [])
    {
        $this->model = $model;

        $tag = $this->open($url, $attributes);
        return $tag;
    }
411365
public function create(array $attributes = [])
    {
        $instance = $this->model->newInstance($attributes)->setConnection(
            $this->query->getConnection()->getName()
        );

        $instance->save();

        return $instance;
    }
652461
public function newFromBuilder($attributes = [])
    {
        $instance = $this->newInstance([], true);

        $instance->setRawAttributes((array) $attributes, true);

        return $instance;
    }
688106
public function setAttributes($attributes)
    {
        if (! is_array($attributes)) {
            $attributes = [$attributes];
        }

        $this->attributes = $attributes;

        return $this;
    }
170164
protected function getModelAbilityKeys($abilities, $model, array $attributes)
    {
        $abilities = Collection::make(is_array($abilities) ? $abilities : [$abilities]);

        $models = Collection::make(is_array($model) ? $model : [$model]);

        return $abilities->map(function ($ability) use ($models, $attributes) {
            return $models->map(function ($model) use ($ability, $attributes) {
                return $this->getModelAbility($ability, $model, $attributes)->getKey();
            });
        })->collapse()->all();
    }
985055
public function newFromBuilder($attributes = [], $connection = null)
    {
        $attributes = (array) $attributes;

        if (! empty($attributes['type'])
            && isset(static::$models[$attributes['type']])
            && class_exists($class = static::$models[$attributes['type']])
        ) {
            /** @var Post $instance */
            $instance = new $class;
            $instance->exists = true;
            $instance->setRawAttributes($attributes, true);
            $instance->setConnection($connection ?: $this->connection);

            return $instance;
        }

        return parent::newFromBuilder($attributes, $connection);
    }
156066
protected function createAbility($ability, $entity, $attributes)
    {
        return Models::ability()->createForModel($entity, $attributes + [
            'name' => $ability,
        ]);
    }
1320564
public function copyForUpdateTo( $model, $attributes = [] ) {

		foreach ( $attributes as $attribute ) {

			$model->setAttribute( $attribute, $this->getAttribute( $attribute ) );
		}
	}
683464
public function newInstance($attributes = [], $exists = false): Model{
        /** @var Model $model */
        $model = parent::newInstance($attributes, $exists);
        $model->applyTypeSettings();
        return $model;
    }
1338617
public static function createFromModel(Model $model)
    {
        $table = $model->getTable();

        $dc = new static($table);

        $dc->strTable = $model->getTable();
        $dc->activeRecord = $model;
        $dc->intId = $model->id;

        return $dc;
    }
231079
public function withAttributes(array $attributes): self
    {
        $result = clone $this;
        $result->attributes = new ParameterCollection($attributes);

        return $result;
    }
867163
public function setAttributes($attributes)
    {
        if (isset($attributes['class'])) {
            $class = $attributes['class'];
            $this->setClass([$class]);
            unset($attributes['class']);
        }
        $this->attributes = $attributes;
        return $this;
    }
477985
public function newFromBuilder($attributes = array(), $connection = null)
    {
        // We change the creation behavior here by replacing the newInstance call.
        // Instead we create the model directly here. This is to enable
        // single table inheritance.
        $modelName = $this->determineModelName((array)$attributes);

        // This part handles what essentially happens in the newInstance call.
        $model = new $modelName([]);
        $model->exists = true;

        // Rest is the same
        $model->setRawAttributes((array)$attributes, true);

        $model->setConnection($connection ?: $this->connection);

        return $model;
    }