/** * Run the database seeds. * * @return void */ public function run() { DB::table('owns')->delete(); Own::create(array('user_id' => '1', 'book_id' => '1')); Own::create(array('user_id' => '1', 'book_id' => '2')); Own::create(array('user_id' => '1', 'book_id' => '3')); Own::create(array('user_id' => '2', 'book_id' => '1')); }
/** * profile for user */ public function profile(Request $request, $id) { $id = Auth::id(); $data['user'] = User::find($id); $allBooks = \DB::table('books')->where('approved', true)->orderBy('created_at', 'desc')->get(); $booksToApprove = \DB::select('select * from bookstore.books where approved = 0'); $owns = Own::all(); if (!$data['user']) { return redirect('/'); } // if ($request -> user() && $data['user'] -> id == $request -> user() -> id) { // $data['author'] = true; // } else { // $data['author'] = null; // } $data['admin'] = false; if ($request->user() && $data['user']->id == $request->user()->id) { if ($data['user']->name == 'admin' && $data['user']->email == '*****@*****.**') { $data['admin'] = true; } } $bookIds = array(); foreach ($owns as $own) { if ($own->user_id == $id) { array_push($bookIds, $own->book_id); } } $books = array(); foreach ($bookIds as $id) { $book = \DB::select('select * from bookstore.books where id = ' . $id); if (!empty($book)) { array_push($books, $book[0]); } } // $data['comments_count'] = $data['user'] -> comments -> count(); // $data['posts_count'] = $data['user'] -> posts -> count(); // $data['posts_active_count'] = $data['user'] -> posts -> where('active', '1') -> count(); // $data['posts_draft_count'] = $data['posts_count'] - $data['posts_active_count']; // $data['latest_posts'] = $data['user'] -> posts -> where('active', '1') -> take(5); // $data['latest_comments'] = $data['user'] -> comments -> take(5); // return view('admin.profile', $data); return view('user.profile', ['books' => $books, 'admin' => $data['admin'], 'allBooks' => $allBooks, 'booksToApprove' => $booksToApprove]); }