<?php

namespace App\Admin\Renderable\User;

use App\Models\User;
use Encore\Admin\Widgets\Table;
use Illuminate\Contracts\Support\Renderable;

class Rule implements Renderable
{

    public function render($key = null)
    {
        $user  = User::find($key);
        $codes = $user->code->map(function ($code) {
            return $code->only(['name', 'code', 'profit']);
        });
        $table = new Table(['名称', '规则项', '分润金额(元)'], $codes->toArray());

        return $table->render();
    }

}