<?php

namespace App\Http\Controllers\backend;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Yajra\DataTables\Facades\DataTables;
use App\Kategori;
use App\Katartikel;
use App\User;
use App\Eoffice;
use App\Forum;
use APpp\Komentar;
use App\ForumEoffice;
use Carbon\Carbon;
use OjiSatriani\Fungsi;
use Illuminate\Support\Str;
use Validator;

class forumEofficeController extends Controller
{
    public function index(Request $request)
    {
        $eoffice = ForumEoffice::all();

        return view('backend.frm-eoffice.index', compact('eoffice'));
    }

    public function data(Request $request)
    {
       // if ($request->ajax()) {
            $eoffice = ForumEoffice::orderBy('id','desc');
            return Datatables::of($eoffice);

       }
    public function create()
    {
        return view('backend.frm-eoffice.tambah');
    }
    

    //    public function postkomentar(Request $request)
    //    {
    //        $request->request->add(['user_id' => auth()->user()->id]);
           
    //        $komentar = Komentar::create();
           
    //        return view('backend.forumeoffice.view', compact('komentar'));
    //    }

     /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
      //  $katartikel = katartikel('id');
       $validator = Validator::make($request->all(), [
          
         
          'judul' => 'required',
          'konten'=> 'required',
          
             
          ]);
          $request->request->add(['user_id' => auth()->user()->id]);
     
          

          if (ForumEoffice::create($request->all())) {
            $respon = array('status'=>true, 'pesan' => ['msg' => 'Data berhasil disimpan']);
        } else {
            $respon = array('status'=>false, 'pesan' => ['msg' => 'Data gagal disimpan']);
        }
      
        return response()->json($respon);
    }

    // public function show(Request $request, $id){
    //       $request->request->add(['user_id' => auth()->user()->id]);
  
    //        $eoffice = ForumEoffice::all()->find($id);
    //         dd($eoffice);      
    //        return view('backend.frm-eoffice.view/{{$id}}', compact('eoffice'));
    //    }

    public function edit($id)
        {
            $eoffice = ForumEoffice::find($id);
            return view('backend.frm-eoffice.ubah', compact('eoffice', $eoffice));
        }
        
    public function view(forumeoffice $forumeoffice, Request $reques, $id)
    {  
        $forumeoffice = ForumEoffice::find('id');

            return view('backend.frm-eoffice.view', compact(['forumeoffice']));   
    }

    public function detail(Request $request)
    {
        $forumEoffice = ForumEoffice::find($id)->forumEoffice;
        return view('backend.frm-eoffice.view', compact(['forumeoffice']));
    }
    
   
}
