<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\ForumFrontend;
use App\User;
use Validator;

class forumFrontendController extends Controller
{
    public function index(Request $request)
    {
        $frontend = ForumFrontend::all();

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

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

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

    //    public function postkomentar(Request $request)
    //    {
    //        $request->request->add(['user_id' => auth()->user()->id]);
           
    //        $komentar = Komentar::create();
           
    //        return view('frontend.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 (ForumFrontend::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]);
  
           $frontend = ForumFrontend::find($id)->frontend();
  
           return view('backend.frm-frontend.view', compact('frontend'));
       }

    public function edit($id)
        {
            $frontend = ForumFrontend::find($id);
            return view('frontend.frm-frontend.ubah', compact('frontend', $frontend));
        }
}
