/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $student = Student::find($id); if ($student == NULL) { throw new Exception('Invalid Student ID'); } $student->year = (int) substr($student->year, 2, 4); $student_category = StudentCategories::find($student->category); $student->category = $student_category->category; $student_branch = Branch::find($student->branch); $student->branch = $student_branch->branch; if ($student->rejected == 1) { unset($student->approved); unset($student->books_issued); $student->rejected = (bool) $student->rejected; return $student; } if ($student->approved == 0) { unset($student->rejected); unset($student->books_issued); $student->approved = (bool) $student->approved; return $student; } unset($student->rejected); unset($student->approved); $student_issued_books = Logs::select('book_issue_id', 'issued_at')->where('student_id', '=', $id)->orderBy('time_stamp', 'desc')->take($student->books_issued)->get(); foreach ($student_issued_books as $issued_book) { $issue = Issue::find($issued_book->book_issue_id); $book = Books::find($issue->book_id); $issued_book->name = $book->title; $issued_book->issued_at = date('d-M', $issued_book->issued_at); } $student->issued_books = $student_issued_books; return $student; }
public function showEditForm($id) { if ($id != null) { $book = Books::find($id); //return var_dump($book->title); return View::make('library.edit')->with('bookInfo', $book); } else { return Redirect::to('books'); } }
public function index() { $logs = Logs::select('id', 'book_issue_id', 'student_id', 'issued_at')->where('return_time', '=', 0)->orderBy('issued_at', 'DESC'); $logs = $logs->get(); for ($i = 0; $i < count($logs); $i++) { $issue_id = $logs[$i]['book_issue_id']; $student_id = $logs[$i]['student_id']; // to get the name of the book from book issue id $issue = Issue::find($issue_id); $book_id = $issue->book_id; $book = Books::find($book_id); $logs[$i]['book_name'] = $book->title; // to get the name of the student from student id $student = Student::find($student_id); $logs[$i]['student_name'] = $student->first_name . ' ' . $student->last_name; // change issue date and return date in human readable format $logs[$i]['issued_at'] = date('d-M', $logs[$i]['issued_at']); $logs[$i]['return_at'] = date('d-M', $logs[$i]['issued_at'] + 1209600); } return $logs; }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $issue = Issue::find($id); if ($issue == NULL) { throw new Exception('Invalid Book ID'); } $issue->added_at_timestamp = date('d-M-y h:i A', strtotime($issue->added_at_timestamp)); $book = Books::find($issue->book_id); $issue->book_name = $book->title; $issue->author = $book->author; $issue->category = Categories::find($book->category_id)->category; $issue->available_status = (bool) $issue->available_status; if ($issue->available_status == 1) { return $issue; } $conditions = array('return_time' => 0, 'book_issue_id' => $id); $book_issue_log = Logs::where($conditions)->take(1)->get(); foreach ($book_issue_log as $log) { $student_id = $log->student_id; } $student_data = Student::find($student_id); unset($student_data->email_id); unset($student_data->books_issued); unset($student_data->approved); unset($student_data->rejected); $student_branch = Branch::find($student_data->branch)->branch; $roll_num = $student_data->roll_num . '/' . $student_branch . '/' . substr($student_data->year, 2, 4); unset($student_data->roll_num); unset($student_data->branch); unset($student_data->year); $student_data->roll_num = $roll_num; $student_data->category = StudentCategories::find($student_data->category)->category; $issue->student = $student_data; return $issue; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // delete $books = Books::find($id); $books->delete(); // redirect Session::flash('message', 'Ha sido borrado de la base de datos!'); return Redirect::to('books'); }
$p->save(); // class Route extends Illuminate\Database\Eloquent\Model { // // public static $table = 'routes'; // public static $key = 'ROUTEID; // } // $r = new Route(); // $r->ROUTECODE = '0011'; // $r->ROUTENAME = 'test11'; // $r->save(); exit; // Create the Books model class Books extends Illuminate\Database\Eloquent\Model { public $timestamps = true; } // Grab a book with an id of 1 $book = Books::find(4); // Change some stuff $book->name = "The Best Book in the World"; $book->author = "Ed Zynda"; $book->touch(); // $book->created_at = R::isoDate(); // Save it to the database $book->save(); // $b = new Books(); // $b->name = 'test'; // $b->author="testauthor"; // $b->save(); // $rs = \Books::all(); // var_dump($rs); // var_dump($book);
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $book = Books::find($id); if (!$book) { return Redirect::to('/')->with('error', Lang::get('labels.booknotfound')); } $book->delete(); return Redirect::to('/')->with('success', Lang::get('labels.bookremoved')); }
public static function getList($fields = array(), $value = NULL) { $where = Books::getWhere($value); // условия поиска $books = Books::find($where); // резулитат поиска $list = '<table class=\'book-list\'>'; // заголовок таблицы if (!$fields) { $fields = Books::$dbFields; } Books::addTitlesToTable($fields, $list); // список книг foreach ($books as $book) { $list .= "<tr>"; foreach ($fields as $field) { if (property_exists($book, $field)) { $list .= "<td>{$book->{$field}}</td>"; } } $list .= "</tr>"; } $list .= '</table>'; return $list; }
<?php include 'database.php'; class Books extends Illuminate\Database\Eloquent\Model { public $timestamps = true; } // Create the Books model // Grab a book with an id of 1 // $book = Books::find(1); // var_dump($book); // Change some stuff // $book->name = "The Best Book in the World"; // $book->author = "Ed Zynda"; // Save it to the database // $book->save(); // $books = Books::all(); $books = Books::find(1); $books->touch(); $books = Books::find(2); $books->touch(); $books = Books::find(3); $books->touch(); // foreach ($books as $book) // { // echo $book->author; // } $books = Books::all(); $bar = $books->toJson(); var_dump($bar); var_dump($capsule);
$user_type = Auth::user()->user_type; if ($user_type == 'user') { return Redirect::to('home')->with('message', 'You are not a admin user. you not have right to do this action'); } } }); Route::filter('book_owner', function ($route) { $book_id = $route->getParameter('id'); if (Auth::check()) { //check if the user is an admin or not $user_type = Auth::user()->user_type; if ($user_type == 'user') { //check if user is the book owner $user_email = Auth::user()->email; $book = Books::find($book_id); //return var_dump($book); $owner_email = $book->user_email; if ($user_email != $owner_email) { return Redirect::to('books')->with('message', 'you are not the owner of this book'); } } } }); Route::filter('auth.basic', function () { return Auth::basic(); }); /* |-------------------------------------------------------------------------- | Guest Filter |--------------------------------------------------------------------------
public function destroy($id) { $books = Books::find($id); $books->delete(); return Redirect::route('books.index'); }