<?php

namespace App\Http\Controllers\Api\Front;

use App\Http\Controllers\Controller;
use App\Http\Transformers\Front\CityTransformer;
use App\Models\Area;
use App\Models\City;
use Illuminate\Http\Request;

class AreaController extends Controller
{

    public function cities()
    {
        $cities = new  City();
        $cities = $cities->has('areas')->get();
        $cities = fractal()
            ->collection($cities)
            ->transformWith(new CityTransformer())
            ->toArray();
        return $this->dataResponse($cities, null, 200);

    }

    public function areas(Request $request)
    {
        $areas = new  Area();
        if ($request->has('city_id')) {
            $areas = $areas->where('city_id', $request->city_id);
        }
        $areas = $areas->get();
        $areas = fractal()
            ->collection($areas)
            ->transformWith(new \App\Http\Transformers\Front\AreaTransformer())
            ->toArray();
        return $this->dataResponse($areas, null, 200);

    }

}
