<?php

namespace App\Http\Controllers\Backend;

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

class forumLaravelController extends Controller
{
    public function index(Request $request)
    {
        $laravel = ForumLaravel::all();

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

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

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

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