Example #1
0
 public function postAddBook()
 {
     if (\Auth::check()) {
         $data = Input::all();
         array_pop($data);
         $rules = ['book_id' => 'required', 'book_name' => 'required', 'book_desc' => 'required', 'mail' => 'required'];
         $validator = Validator::make($data, $rules);
         if ($validator->fails()) {
             return Redirect::back()->withErrors($validator->errors())->withInput();
         } else {
             $arrival = new Arrivals();
             $arrival->book_id = $data['book_id'];
             $arrival->book_name = $data['book_name'];
             $arrival->book_desc = $data['book_desc'];
             $arrival->save();
             if ($data['mail'] == 0) {
                 $staffs = Staff::Orderby('id', 'des')->get();
                 foreach ($staffs as $staff) {
                     Mail::send('mail.mail', array('name' => $staff->name, 'book_name' => $data['book_name']), function ($message) use($staff) {
                         $message->to($staff->email, $staff->name)->subject('Library Notification');
                     });
                 }
             } elseif ($data['mail'] == 1) {
                 $students = Student::Orderby('id', 'des')->get();
                 foreach ($students as $student) {
                     Mail::send('mail.mail', array('name' => $student->name, 'book_name' => $data['book_name']), function ($message) use($student) {
                         $message->to($student->email, $student->name)->subject('Library Notification');
                     });
                 }
             } else {
                 $staffs = Staff::Orderby('id', 'des')->get();
                 foreach ($staffs as $staff) {
                     Mail::send('mail.mail', array('name' => $staff->name, 'book_name' => $data['book_name']), function ($message) use($staff) {
                         $message->to($staff->email, $staff->name)->subject('Library Notification');
                     });
                 }
                 $students = Student::Orderby('id', 'des')->get();
                 foreach ($students as $student) {
                     Mail::send('mail.mail', array('name' => $student->name, 'book_name' => $data['book_name']), function ($message) use($student) {
                         $message->to($student->email, $student->name)->subject('Library Notification');
                     });
                 }
             }
             Session::flash('err', "1");
             return redirect('add_books');
         }
     } else {
         return redirect('login');
     }
 }
Example #2
0
 public function getViewBook($id)
 {
     $menu = Menu::Orderby('id', 'des')->get();
     $book = Arrivals::where('id', $id)->get()[0]->book_name;
     $book_id = Arrivals::where('id', $id)->get()[0]->book_id;
     $book_desc = Arrivals::where('id', $id)->get()[0]->book_desc;
     if (\Auth::Check()) {
         $user = User::where('username', Session::get('username'))->first();
         return view('view_book', ['book' => $book, 'book_id' => $book_id, 'book_desc' => $book_desc])->with('username', $user->username)->with('level', $user->level)->with('menu', $menu);
     } else {
         return redirect('login');
     }
 }