<?php

namespace App\Http\Controllers;


use App\Models\LeadType;
use Request;


class LeadTypeController extends Controller
{

    public function __construct()
    {
        $this->middleware('admin');
    }

    public function index()
    {

        $data = [
            'values' => LeadType::all(),
        ];
        return view('admin.lead.types', $data);
    }

    public function store()
    {

        $data = Request::all();
        if($data['id'] === "new"){
            $model = LeadType::create([
                'name' => $data['name'],
                'active' => isset($data['active']) ? true : false,
            ]);
        }else{
            $model = LeadType::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_lead_types'));


    }
}