Pass an argument to the fractal transformer transform method

I use fractal flem packaging. I have a conversion class setting like this

class ConversationTransformer extends TransformerAbstract { public function transform (Conversation $conversation, $user) { return []; } } 

however I get the absence of argument 2 exception to convert when trying to access it

 $user = $this->people->get($this->user()); //conversations $conversations = $this->conversations->user($user); return $this->fractal->paginatedCollection($conversations, $user, new ConversationTransformer()); 
+7
rest api php
source share
1 answer
 class ConversationTransformer extends TransformerAbstract { private $params = []; function __construct($params = []) { $this->params = $params; } public function transform (Conversation $conversation) { //-- $this->params will be used here return []; } } 

Call it with this return:

  return $this->fractal->paginatedCollection($conversations, new ConversationTransformer(['user' => $user])) 
+11
source share

All Articles