<?php

namespace App\Http\Controllers\Settings;

use App\Http\Controllers\Controller;

use App\Models\TravelCountry;
use App\Models\TravelNationality;
use App\Models\TravelNationalityRequirement;
use Carbon\Carbon;
use HTMLHelper;
use Input;

class TravelNationalityController extends Controller
{
    public function __construct()
    {
       $this->middleware('admin');

    }

    public function index($step = false)
    {
        $data = [
            'travel_nationality' => TravelNationality::all(),
        ];
        return view('settings.travel_nationality.index', $data);
    }


    public function update(){

        $data = Input::all();
        if($data['id'] == "new"){
            $model = TravelNationality::create([
                'name' => $data['name'],
                'active' => isset($data['active']) ? true : false,
            ]);
        }else{
            $model = TravelNationality::find($data['id']);
            $model->name = $data['name'];
            $model->active = isset($data['active']) ? true : false;
            $model->save();
        }

        \Session()->flash('alert-save', '1');
        return redirect(route('admin_settings_travel_nationality'));
    }

    public function delete($id){

       if(TravelNationalityRequirement::where('travel_nationality_id', $id)->count()){
            \Session()->flash('alert-error', 'Eintrag wird verwendet');
            return redirect()->back();
        }
        $model = TravelNationality::findOrFail($id);
        $model->delete();
        \Session()->flash('alert-success', 'Eintrag gelöscht');
        return redirect()->back();

    }

}


