/** * заполнение таблицы пранзакций */ private function transactionsTable() { Transaction::truncate(); $u = User::count(); $c = Card::count(); $i = 0; while ($i < 10) { ++$i; Transaction::create(['user_id' => rand(1, $u), 'card_id' => rand(1, $c), 'money' => rand(0, 1000)]); } $crd = Card::all(); foreach ($crd as $v) { $v->balance = Transaction::where('card_id', $v->id)->sum('money'); $v->save(); } }
/** * Returns an integer representing the number of * cards in the database. * * @return mixed count of how many cards there are */ public function getCardCount() { // return the number of cards in the DB via // eloquent's count() function return \App\Card::count(); }
* Example3Controller.php * * This is nice because instead of having an entry for every route related * to a given controller, you can dynamically generate them based on your * controller functions. * * The rest of the examples will be located inside Example3Controller.php. * * Please note that this very often the best way to setup your routes. */ Route::controller('example3', 'Example3Controller'); /** * route for form controller. basically the same thing as the above. */ Route::controller('form', 'FormController'); Route::get('/', 'HomeController@index'); /** * routes for user auth, card, and playlist based functions */ Route::controllers(['auth' => 'Auth\\AuthController', 'password' => 'Auth\\PasswordController', 'card' => 'CardController', 'playlist' => 'PlaylistController']); Route::get('/ajax', function () { return view('ajax')->with('count', \App\Card::count()); }); /** * a quick route to test new code. * * I usually use this route as a scratch pad and quick testing ground when * I'm testing out a new idea, or trying to isolate a problem in my code. */ Route::get('/workspace', function () { });