<?php

namespace Modules\Mall\Http\Controllers\Admin;

use Encore\Admin\Controllers\AdminController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Modules\Mall\Models\Region;

class RegionController extends AdminController
{

    public function ajax(Request $request)
    {
        $q = $request->q;

        return Region::where('name', 'like', "%$q%")->paginate(null, ['id', 'name as text']);
    }

    public function region(Request $request)
    {
        $regionId = $request->get('q');

        return Region::where('parent_id', $regionId)->get(['id', DB::raw('name as text')]);
    }

}
