<?php

namespace App\Http\Controllers\Settings;

use App\Http\Controllers\Controller;

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

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

    }

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


    public function update(){

        $data = Input::all();
        if($data['id'] == "new"){
            $model = TravelAgenda::create([
                'name' => $data['name'],
                'active' => isset($data['active']) ? true : false,
                'travelcountry_id' => $data['travelcountry_id'],

            ]);
        }else{
            $model = TravelAgenda::find($data['id']);
            $model->name = $data['name'];
            $model->active = isset($data['active']) ? true : false;
            $model->travelcountry_id = $data['travelcountry_id'];
            $model->save();
        }

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

    public function delete($id){

      if(Booking::where('travelagenda_id', $id)->count()){
            \Session()->flash('alert-error', 'Eintrag wird verwendet');
            return redirect()->back();
        }

        $model = TravelAgenda::findOrFail($id);
        $model->delete();
        \Session()->flash('alert-success', 'Eintrag gelöscht');
        return redirect()->back();
    }

}


