Advertisement
fadlyshafa

Untitled

Oct 30th, 2019
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. ....
  2. public function store($id){
  3.         $cek = \DB::table('m_buku')->where('id',$id)->where('stock','>',0)->where('status',1)->count();
  4.  
  5.         if($cek > 0){
  6.             \DB::table('peminjaman')->insert([
  7.                 'buku'=>$id,
  8.                 'user'=>\Auth::user()->id,
  9.                 'created_at'=>date('Y-m-d H:i:s')
  10.                 ]);
  11.  
  12.             $buku = \DB::table('m_buku')->where('id',$id)->first();
  13.             $qty_now = $buku->stock;
  14.             $qty_new = $qty_now - 1;
  15.  
  16.             \DB::table('m_buku')->where('id',$id)->update([
  17.                 'stock'=>$qty_new
  18.             ]);
  19.  
  20.             \Session::flash('sukses','buku berhasil di pinjam');
  21.  
  22.             return redirect('master/buku');
  23.         }else{
  24.             \Session::flash('gagal','buku sudah habis atau tidak aktif');
  25.  
  26.             return redirect('master/buku');
  27.         }
  28.     }
  29. ....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement