SHARE
TWEET

Untitled

fadlyshafa Jan 17th, 2020 106 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.  
  7. use App\Models\Paket;
  8.  
  9. class Paket_controller extends Controller
  10. {
  11.     public function index(){
  12.         $title = 'Paket Laundry';
  13.         $data = Paket::get();
  14.  
  15.         return view('paket.index',compact('title','data'));
  16.     }
  17.  
  18.     public function add(){
  19.         $title = 'Tambah Paket Laundry';
  20.  
  21.         return view('paket.add',compact('title'));
  22.     }
  23.  
  24.     public function store(Request $request){
  25.         $this->validate($request,[
  26.             'nama'=>'required',
  27.             'harga'=>'required'
  28.         ]);
  29.  
  30.         $data['id'] = \Uuid::generate(4);
  31.         $data['nama'] = $request->nama;
  32.         $data['harga'] = $request->harga;
  33.         $data['created_at'] = date('Y-m-d H:i:s');
  34.         $data['updated_at'] = date('Y-m-d H:i:s');
  35.  
  36.         \Session::flash('sukses','Data berhasil ditambah');
  37.  
  38.         Paket::insert($data);
  39.  
  40.         return redirect('paket-laundry');
  41.     }
  42.  
  43.     public function edit($id){
  44.         $dt = Paket::find($id);
  45.         $title = "Edit Paket $dt->nama";
  46.  
  47.         return view('paket.edit',compact('title','dt'));
  48.     }
  49.  
  50.     public function update(Request $request,$id){
  51.         $this->validate($request,[
  52.             'nama'=>'required',
  53.             'harga'=>'required'
  54.         ]);
  55.        
  56.         $data['nama'] = $request->nama;
  57.         $data['harga'] = $request->harga;
  58.         $data['updated_at'] = date('Y-m-d H:i:s');
  59.  
  60.         Paket::where('id',$id)->update($data);
  61.  
  62.         \Session::flash('sukses','Data berhasil di update');
  63.  
  64.         return redirect('paket-laundry');
  65.     }
  66.  
  67.     public function delete($id){
  68.         try {
  69.             Paket::where('id',$id)->delete();
  70.  
  71.             \Session::flash('sukses','Data berhasil dihapus');
  72.         } catch (\Exception $e) {
  73.             \Session::flash('gagal',$e->getMessage());
  74.         }
  75.  
  76.         return redirect('paket-laundry');
  77.     }
  78. }
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
Top