<?php

namespace Modules\Admin\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Modules\Main\Models\City;
class AdminCitiesController extends Controller
{
    public function index(Request $request)
    {
        $cities = City::orderBy('name');
        switch ( $request->filter )
        {
            case 'trashed':
                $cities->onlyTrashed();
                break;
            case 'actual':
                break;
            default:
                $cities->withTrashed();
                break;
        }
        //}
        $cities = $cities->get();
        return view('admin::cities.index', [
            'cities' => $cities,
            'filter' => $request->filter
        ]);
    }

    public function update(Request $request, City $city)
    {
        $city->update($request->only('name'));
        return back();
    }

    public function create(Request $request)
    {
        $city = City::create($request->only('name'));
        return to_route('admin.cities');
    }

    public function delete(City $city)
    {
        $city->delete();
        return to_route('admin.cities');
    }

    public function restore(City $city)
    {
        $city->restore();
        return to_route('admin.cities');
    }

}
