<?php

namespace App\Http\Controllers\EndoINDEX;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;


class FunctionController extends Controller
{
    public function __construct(Request $r){checklogin();}
    public function index(){

        $view['tb_function']    = DB::table('tb_function')->get();
        $view['users']          = DB::table('users')->get();
        return view('endoindex.function.index',$view);
    }
    public function show($id){
        return view('endoindex.function.show');
    }
    public function store(Request $r){
        if($r->event=="createfunction"){$this->createfunction($r);}
        return redirect(url('function'));
    }

    public function createfunction($r){
        $val['function_name'] = $r->function_name;
        DB::table('tb_function')->insert($val);
    }

    ///// สร้าง function ในการช่วยอัพโหลดรูปภาพ
    public function create(){
        return view('endoindex.function.create');
    }

}
