<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Yajra\DataTables\Facades\DataTables;
use App\User;
use App\ForumTeknis;
use Validator;

class forumTeknisController extends Controller
{
    public function index(Request $request)
    {
        $teknis = ForumTeknis::all();

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

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

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

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