SHARE
TWEET

Untitled

a guest Oct 22nd, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6. use App\Models\Employee;
  7.  
  8. class EmployeeController extends Controller
  9. {
  10.     function index(){
  11.         if(\Auth::check()){
  12.             //return 'sudah login'
  13.  
  14.             $data['level'] = \Auth::user()->level;
  15.  
  16.         $data['employees'] = Employee::paginate(4);
  17.         $data['header'] = 'List Pegawai';
  18.         return view('employee.index',$data);
  19.         }else{
  20.             return 'belum login';
  21.         }
  22.         // $data['employees'] = ['andro','bower','charlie'];
  23.  
  24.     }
  25.  
  26.     function create(){
  27.         $data['units'] = \App\Models\Unit::pluck('name','id');
  28.         $data['departemens'] = \App\Models\Departemen::pluck('name','id');
  29.         return view('employee.create',$data);
  30.     }
  31.  
  32.     function store(Request $request){
  33.         $request->validate([
  34.             'name'  => 'required',
  35.             'nip'  => 'required|min:5|integer|unique:employees',
  36.             'address'  => 'required',
  37.             'bdate'  => 'required'
  38.  
  39.         ]);
  40.  
  41.         // return $request->all();
  42.         // $employee = new Employee();
  43.         // $employee->nip = $request->nip;
  44.         // $employee->name = $request->name;
  45.         // $employee->bdate = $request->bdate;
  46.         // $employee->address = $request->address;
  47.         // $employee->gender = $request->gender;
  48.         // $employee->save();
  49.        
  50.         Employee::create($request->all());
  51.  
  52.         return redirect('/employee')->with('message','Success Add Record');
  53.     }
  54.  
  55.     function edit($id){
  56.         $data['employee'] = Employee::find($id);
  57.         $data['units'] = \App\Models\Unit::pluck('name','id');
  58.         $data['departemens'] = \App\Models\Departemen::pluck('name','id');
  59.         return view('employee.edit', $data);
  60.     }
  61.  
  62.     function update($nip, request $request){
  63.         $employee = Employee::find($nip);
  64.         $employee->update($request->all());
  65.         return redirect('/employee')->with('message','Success Edit !!!');
  66.     }
  67.    
  68.     function destroy($nip){
  69.         $employee = Employee::find($nip);
  70.         $employee->delete();
  71.         return redirect('/employee')->with('message','Record has Deleted!!!');
  72.     }
  73. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top