Skip to content

Commit

Permalink
add attachAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
milwad-dev committed Mar 15, 2023
1 parent 49651fc commit 8d18334
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/Traits/Attributable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ trait Attributable
use HasRelationships;

/**
* First or create attributes.
* Get attributes
*
* @return MorphMany
*/
public function attributes()
{
return $this->morphMany(Attribute::class , 'attributable', 'attributable');
}

/**
* Attach attribute.
*
* @param string $title
* @param string $value
Expand All @@ -31,14 +41,16 @@ public function attachAttribute(string $title, string $value)
return Attribute::query()->create($attributes);
}


/**
* Get attributes
* Attach multiple attributes.
*
* @return MorphMany
* @param array $values
* @return bool
*/
public function attributes()
public function attachAttributes(array $values)
{
return $this->morphMany(Attribute::class , 'attributable', 'attributable');
return Attribute::query()->insert($values);
}

/**
Expand Down

0 comments on commit 8d18334

Please sign in to comment.