Example #1
0
 public function ownThisBookFromDetails()
 {
     $currentUserId = Auth::id();
     $bookIdToOwn = $_POST['bookIdToOwn'];
     $datetime = new \DateTime();
     $datetime->setTimeZone(new \DateTimeZone('Europe/Skopje'));
     $owns = DB::select('select * from bookstore.owns where book_id = ' . $bookIdToOwn . ' and user_id =' . $currentUserId);
     if (sizeof($owns) == 0) {
         $idTag = DB::table('owns')->insertGetId(array('book_id' => $bookIdToOwn, 'user_id' => $currentUserId, 'created_at' => $datetime, 'updated_at' => $datetime));
     } else {
         DB::table('owns')->where('book_id', $bookIdToOwn)->where('user_id', $currentUserId)->update(array('updated_at' => $datetime));
     }
     $path = '/book/' . $bookIdToOwn;
     header("Location: " . $path);
     exit;
 }