Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ....
- public function store($id){
- $cek = \DB::table('m_buku')->where('id',$id)->where('stock','>',0)->where('status',1)->count();
- if($cek > 0){
- \DB::table('peminjaman')->insert([
- 'buku'=>$id,
- 'user'=>\Auth::user()->id,
- 'created_at'=>date('Y-m-d H:i:s')
- ]);
- $buku = \DB::table('m_buku')->where('id',$id)->first();
- $qty_now = $buku->stock;
- $qty_new = $qty_now - 1;
- \DB::table('m_buku')->where('id',$id)->update([
- 'stock'=>$qty_new
- ]);
- \Session::flash('sukses','buku berhasil di pinjam');
- return redirect('master/buku');
- }else{
- \Session::flash('gagal','buku sudah habis atau tidak aktif');
- return redirect('master/buku');
- }
- }
- ....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement