<?php

namespace App\Admin\Controllers\Ajax;

use App\Models\Area;
use DB;
use Illuminate\Http\Request;

class AreaController
{

    public function children(Request $request)
    {
        $code = $request->get('q');

        return Area::whereHas('parent', function ($q) use ($code) {
            $q->where('code', $code);
        })->get(['code as id', DB::raw('name as text')]);
    }

}
