<?php

namespace App\Http\Controllers\nn_cms;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\nn_site_settings;

class ManagerSiteSettings extends ManagerSiteController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */

    public function index()
    {
        $siteSettings = new nn_site_settings();

        $data['siteSettings'] = $siteSettings::first();

        return view('nn_cms.pages.nn_site_settings.index', $data);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */

    public function update(Request $request)
    {
        $siteSettings = new nn_site_settings();

        $siteSettingsData = $siteSettings::first();

        $data = [
            'email' => $request->get('email'),
            'facebook' => $request->get('facebook'),
            'instagram' => $request->get('instagram'),
            'twitter' => $request->get('twitter'),
            'linkedin' => $request->get('linkedin'),
        ];

        if ($siteSettingsData) {
            $check = $siteSettings::where('id', $siteSettingsData->id)->update($data);
        } else {
            $check = $siteSettings::create($data);
        }

        return $check ? 1 : 0;
    }
}
