Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Introduce Observe attribute for models #49843

Merged
merged 4 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
rename file
  • Loading branch information
taylorotwell committed Feb 9, 2024
commit a9562beefe7758f916d55f95e965511d7778f09f
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Attribute;

#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
class Observe
class ObservedBy
{
/**
* Create a new attribute instance.
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Eloquent/Concerns/HasEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Illuminate\Database\Eloquent\Concerns;

use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Database\Eloquent\Attributes\Observe;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use Illuminate\Events\NullDispatcher;
use Illuminate\Support\Arr;
use InvalidArgumentException;
Expand Down Expand Up @@ -48,7 +48,7 @@ public static function resolveObserveAttributes()
{
$reflectionClass = new ReflectionClass(static::class);

return collect($reflectionClass->getAttributes(Observe::class))
return collect($reflectionClass->getAttributes(ObservedBy::class))
->map(fn ($attribute) => $attribute->getArguments())
->flatten()
->all();
Expand Down
6 changes: 3 additions & 3 deletions tests/Database/DatabaseEloquentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Illuminate\Database\Connection;
use Illuminate\Database\ConnectionResolverInterface;
use Illuminate\Database\ConnectionResolverInterface as Resolver;
use Illuminate\Database\Eloquent\Attributes\Observe;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\ArrayObject;
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
Expand Down Expand Up @@ -3355,13 +3355,13 @@ public function uniqueIds()
}
}

#[Observe(EloquentTestObserverStub::class)]
#[ObservedBy(EloquentTestObserverStub::class)]
class EloquentModelWithObserveAttributeStub extends EloquentModelStub
{
//
}

#[Observe([EloquentTestObserverStub::class])]
#[ObservedBy([EloquentTestObserverStub::class])]
class EloquentModelWithObserveAttributeUsingArrayStub extends EloquentModelStub
{
//
Expand Down
Loading