<?php
/**
 * Created by PhpStorm.
 * User: zilongs
 * Date: 20-10-4
 * Time: 下午9:57
 */

namespace App\Http\Controllers\Api\V1;

use App\Models\ServicePack;
use App\Models\Team;

class ServicePackController extends AuthController
{
    public function servicePackList()
    {
        $data = ServicePack::orderBy('id', 'desc')->paginate();

        return out($data);
    }

    public function servicePackDetail()
    {
        $req = request()->post();
        $this->validate(request(), [
            'service_pack_id' => 'required|integer'
        ]);

        $data = ServicePack::where('id', $req['service_pack_id'])->first()->toArray();
        if (!empty($data['team_id'])) {
            $data['team'] = Team::with(['docter.office', 'docter.qualification'])->whereIn('id', $data['team_id'])->get()->toArray();
        }

        return out($data);
    }
}
