function getExample3() { $books = new \App\Book(); $all_books = $books->all(); foreach ($all_books as $book) { echo $book->title . '<br>'; } return 'Example 3'; }
foreach (Session::get('cart.items') as $key => $item) { if ($item == $id) { Session::forget('cart.items.' . $key); } } return back(); }]); Route::get('/historico', 'HomeController@getHistorico'); //backend Route::get('/backend/', ['middleware' => 'auth.role:4', function () { $books = App\Book::where('active', 0)->get(); $users = App\user::where('active', 0)->get(); return view('admin/home', ['books' => $books, 'users' => $users]); }]); Route::get('/backend/books', ['middleware' => 'auth.role:4', function () { $books = App\Book::all(); return view('admin/listBooks', ['books' => $books]); }]); Route::get('/backend/users', ['middleware' => 'auth.role:4', function () { $users = App\user::all(); return view('admin/listUsers', ['users' => $users]); }]); Route::get('/backend/book/status/{id}', ['middleware' => 'auth.role:4', function ($id) { try { $books = App\Book::where('id', $id)->get(); foreach ($books as $book) { $book->active == 1 ? $book->active = 0 : ($book->active = 1); $book->save(); } } catch (\Exception $e) { return back();
public function index() { $book = new \App\Book(); $books = $book->all(); return view('books')->with('books', $books); }
<?php /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/', function () { return view('welcome'); }); Route::get('/mongo', function () { /*App\Book::create(['name' => 'MongoDB Pro', 'author' => 'Dwight Merriman']);*/ /*$book = App\Book::find('565e8d2d071a58a5788b4570'); $book->author = 'Misko Hevery'; $book->name = 'Fundamentals Of Angular JS'; $book->save();*/ //$book->delete(); $books = App\Book::all()->toArray(); echo '<pre>'; print_r($books); return 'Hello Sir!!'; });
function getBookWithEloquent() { $book = new \App\Book(); echo $book->all(); return 'getBookWithEloquent'; }