Skip to content

Commit

Permalink
[9.x] Adds Attribute::with (#41014)
Browse files Browse the repository at this point in the history
* add with constructor

* Update Attribute.php

* Update DatabaseEloquentModelAttributeCastingTest.php

* Update Attribute.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
bvtterfly and taylorotwell authored Feb 15, 2022
1 parent 0161f3e commit ef7f80a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Illuminate/Database/Eloquent/Casts/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ public function __construct(callable $get = null, callable $set = null)
$this->set = $set;
}

/**
* Create a new attribute accessor / mutator.
*
* @param callable|null $get
* @param callable|null $set
* @return static
*/
public static function make(callable $get = null, callable $set = null): static
{
return new static($get, $set);
}

/**
* Create a new attribute accessor.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class TestEloquentModelWithAttributeCast extends Model

public function uppercase(): Attribute
{
return new Attribute(
return Attribute::make(
function ($value) {
return strtoupper($value);
},
Expand Down

0 comments on commit ef7f80a

Please sign in to comment.