rizal245754733

KaryawanController

May 16th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.95 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6. use App\Karyawan;
  7.  
  8. class KaryawanController extends Controller
  9. {
  10.     /**
  11.      * Display a listing of the resource.
  12.      *
  13.      * @return \Illuminate\Http\Response
  14.      */
  15.     public function index()
  16.     {
  17.         //$karyawan_list = Karyawan::all()->sortByDesc('id'); //sortir data
  18.         $karyawan_list= Karyawan::orderBy('id','desc')->paginate(3);
  19.         $jumlah_karyawan = $karyawan_list->count(); //tampil jumlah data
  20.         return view('chap8.karyawan', compact('halaman', 'karyawan_list', 'jumlah_karyawan'));
  21.     }
  22.     public function cari(Request $request){
  23.         $cari = $request->get('search');
  24.         $karyawan_list = Karyawan::where('nama','LIKE','%'.$cari.'%')->orwhere('nip','LIKE','%'.$cari.'%')->paginate(1);
  25.         $jumlah_karyawan = $karyawan_list->count();
  26.         return view('chap8.karyawan', compact('halaman', 'karyawan_list', 'jumlah_karyawan'));
  27.     }
  28.  
  29.     /**
  30.      * Show the form for creating a new resource.
  31.      *
  32.      * @return \Illuminate\Http\Response
  33.      */
  34.     public function create()
  35.     {
  36.         return view('chap8.create', compact('halaman'));
  37.     }
  38.  
  39.     /**
  40.      * Store a newly created resource in storage.
  41.      *
  42.      * @param  \Illuminate\Http\Request  $request
  43.      * @return \Illuminate\Http\Response
  44.      */
  45.     public function store(Request $request)
  46.     {
  47.         $karyawan=new \App\Karyawan;
  48.         $karyawan->nip = $request->nip;
  49.         $karyawan->nama = $request->nama;
  50.         $karyawan->tgl_lahir = $request->tgl_lahir;
  51.         $karyawan->gender = $request->gender;
  52.         $karyawan->save();
  53.         return redirect('karyawan');
  54.     }
  55.  
  56.     /**
  57.      * Display the specified resource.
  58.      *
  59.      * @param  int  $id
  60.      * @return \Illuminate\Http\Response
  61.      */
  62.     public function show($id)
  63.     {
  64.         $karyawan=Karyawan::findOrFail($id);
  65.         return view('chap8.show', compact('halaman','karyawan'));
  66.     }
  67.  
  68.     /**
  69.      * Show the form for editing the specified resource.
  70.      *
  71.      * @param  int  $id
  72.      * @return \Illuminate\Http\Response
  73.      */
  74.     public function edit($id)
  75.     {
  76.         $karyawan=Karyawan::findOrFail($id);
  77.         return view('chap8.edit',compact('karyawan'));
  78.     }
  79.  
  80.     /**
  81.      * Update the specified resource in storage.
  82.      *
  83.      * @param  \Illuminate\Http\Request  $request
  84.      * @param  int  $id
  85.      * @return \Illuminate\Http\Response
  86.      */
  87.     public function update(Request $request, $id)
  88.     {
  89.         $karyawan=Karyawan::findOrFail($id);
  90.         $karyawan->update($request->all());
  91.         return redirect('karyawan');
  92.     }
  93.  
  94.     /**
  95.      * Remove the specified resource from storage.
  96.      *
  97.      * @param  int  $id
  98.      * @return \Illuminate\Http\Response
  99.      */
  100.     public function destroy($id)
  101.     {
  102.         $karyawan=Karyawan::findOrFail($id);
  103.         $karyawan->delete();
  104.         return redirect('karyawan');
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment