laravel使用dingo/api对data进行transform时报Undefined variable?
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']
];
}
}
报错如下:
请问该怎么修改?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢邀,
$Card
改为$card