<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Session;
use App\Models\Contact;

class ContactController extends Controller
{
     /**
     * Display a listing of the resource.
     */
    public function index()
    {
        $contact = Contact::first();

        if (empty($contact)) {
            $contact = Contact::create([
                'whatsapp' => '0',
                'facebook' => '0',
                'shopee' => '0',
                'instagrma' => '0'
            ]);
        }

        return view('apps.admin.contact.index')->with('contact', $contact);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request)
    {
        $contact = Contact::findOrFail($request->id); 

        $data = $request->all();

        $contact->update($data);

        Session::flash('flash_message', 'Data telah diubah');
        return redirect()->route('admin.contact');
    }
}
