Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use App\Karyawan;
- class KaryawanController extends Controller
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index()
- {
- $karyawan_list = Karyawan::all()->sortBy('id');//sortir Data
- $karyawan_list=karyawan::orderby('id','desc')->paginate(3);
- $jumlah_karyawan = $karyawan_list->count();//tampil jml Data
- return view('chap8.karyawan', compact('halaman', 'karyawan_list','jumlah_karyawan'));
- }
- /**
- * Show the form for creating a new resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function create()
- {
- return view('chap8.create', compact('halaman'));
- }
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(Request $request)
- {
- $karyawan = $request->all();
- return $karyawan;
- }
- /**
- * Display the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function show($id)
- {
- $karyawan=karyawan::findOrFail($id);
- return view('chap8.show',compact('halaman','karyawan'));
- }
- /**
- * Show the form for editing the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function edit($id)
- {
- $karyawan=Karyawan::findOrFail($id);
- return view('chap8.edit', compact('karyawan'));
- }
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request, $id)
- {
- $karyawan=Karyawan::findOrFail($id);
- $karyawan->update($request->all());
- return redirect('karyawan');
- }
- /**
- * Remove the specified resource from storage.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function destroy($id)
- {
- $karyawan=Karyawan::findOrFail($id);
- $karyawan->delete();
- return redirect('karyawan');
- }
- public function search(Request $request){
- $cari = $request->get('search');
- $karyawan_list = Karyawan::where('nama','LIKE','%'.$cari.'%')->orwhere('nip','LIKE','%'.$cari.'%')->paginate(1);
- $jumlah_karyawan = $karyawan_list->count();
- return view('chap8.karyawan', compact('halaman', 'karyawan_list', 'jumlah_karyawan'));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment