<?php

namespace App\Http\Controllers;

use App\Models\District;
use App\Models\Site\HasHome;
use App\Models\Site\NeedHome;
use App\Models\Street;
use App\Models\Town;
use Illuminate\Http\Request;

class HelperController extends Controller
{
    public function getTownsFromCity(Request $request){
        $towns = Town::where('il_id',$request->city_id)->get();
        return response()->json(['success'=>'true','towns'=>$towns]);
    }

    public function getDistrictsFromTown(Request $request){
        $districts = District::where('ilce_id',$request->town_id)->get();
        return response()->json(['success'=>'true','districts'=>$districts]);
    }

    public function getStreetsFromDistrict(Request $request){
        $streets = Street::where('mahalle_id',$request->district_id)->get();
        return response()->json(['success'=>'true','streets'=>$streets]);
    }

    public function basvuruSorgula(){
        if (!isset($_GET['no']))
            return back();
        $check = NeedHome::where('no',$_GET['no'])->first();
        if ($check)
            return view('site.pages.deprem_yardim_formu',['form'=>$check]);

        $check = HasHome::where('no',$_GET['no'])->first();
        if ($check)
            return view('site.pages.evimi_acabilirim',['form'=>$check]);

        return redirect()->route('site.index')->with('error','Kayıt Bulunamadı');
    }
}
