Pass an argument to fractal transformer transform method

后端 未结 1 563
攒了一身酷
攒了一身酷 2021-01-12 07:10

Am using fractal package from phpleague. I have a transform class setup like this

    class ConversationTransformer extends TransformerAbstract
    {

               


        
1条回答
  •  离开以前
    2021-01-12 07:22

    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]))
    

    0 讨论(0)
提交回复
热议问题