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

event(), dispatch(), with JsonResourceCollection #21453

Closed
evgeniy-n opened this issue Sep 29, 2017 · 0 comments
Closed

event(), dispatch(), with JsonResourceCollection #21453

evgeniy-n opened this issue Sep 29, 2017 · 0 comments

Comments

@evgeniy-n
Copy link

  • Laravel Version: 5.5.*
  • PHP Version: 7.10
  • Database Driver & Version:

Description:

Cant pass resource collection to event classes as property, becouse serialization of 'class@anonymous' is not allowed.

Steps To Reproduce:

Create any event class.
Instantiate it with resource collection.
Try to fire event or dispath it.

In code

use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Http\Resources\Json\Resource;

class TestEvent implements ShouldBroadcast {
    protected $value;

   public function __construct($value){
      $this->value = $value;
   }
}

class TestResource extends Resource {}

// Somewhere in Your code
event( new TestEvent( TestResource::collection($anyCollectionObject) ) );
dispatch( new TestEvent( TestResource::collection($anyCollectionObject) ) );

Both calls to helpers will trigger exception:
Serialization of 'class@anonymous' is not allowed.
\Illuminate\Queue\Queue::createObjectPayload() - call serialize on anonymous class of collection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants