0

controller代码如下:

<?php

namespace App\Http\Controllers\Lucky;

use Illuminate\Http\Request;
use App\Http\Controllers\BaseController as BaseController;
use App\Models\Card;
use App\Http\Transformers\CardsTransformer;

class CardsController extends BaseController
{
    public function show(Request $request) {
        $unionId = $request->input('unionId');
        $card = new Card;
        $card->union_id = $unionId;
        $card->fi_card = 1;
        $card->s_card = 2;
        $card->t_card = 3;
        $card->fo_card = 4;
        $card->save();
        $a = new CardsTransformer();
        $b = $a->transform($card);

        return $this->response->array(['code'=>0,'msg'=>'OK','data'=>$b]);
    }
}

transformer代码如下:

<?php

namespace App\Http\Transformers;

use League\Fractal\TransformerAbstract;
use App\Models\Card;

class CardsTransformer extends TransformerAbstract
{
    public function transform(Card $Card) {
        return [
            'unionId' => $card['union_id'],
            'fiCard' => $card['fi_card'],
            'sCard' => $card['s_card'],
            'tCard' => $card['t_card'],
            'foCard' => $card['fo_card']
        ];
    }
}

报错如下:

clipboard.png

请问该怎么修改?

1月15日提问
1 个回答
0

已采纳

谢邀,
$Card改为$card

撰写答案

推广链接