<?php

namespace App\Http\Controllers\Backend;

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

class forumBackendController extends Controller
{
    public function index(Request $request)
    {
        $backend = ForumBackend::all();

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

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

       }
    public function create()
    {
        return view('backend.frm-backend.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 (ForumBackend::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]);
  
           $backend = ForumBackend::all();
  
           return view('backend.frm-backend.view', compact('forumbackend', $forumbackend));
       }

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